Functional Programming in Python, for Education
Project description
FuPy: Functional Programming in Python, for Education
Overview
- Documentation
- For some examples, see demo.py.
Python offers (limited) support for functional programming:
- functions are first-class citizens;
- functions can take functions as arguments and can return functions
- lambda expressions for anonymous functions
FuPy aims to overcome some limitations, by adding:
- basic types and type constructors
Emptytype without valuesUnittype with valueunitEither[A, B](disjoint sum) typeBoth[A, B](product) type (tuple)Func[A, B]function space type
- function composition and other function combinators
@for head-to-tail composition, also written as ⚬&for split, also written as △|for case, also written as ▽*for product (functor over product/tuple type), also written as ⨯
+for sum (functor over sum/Either type), also written as +**for iterated composition, also written with a superscript^for functorial exponentiation
- auto (un)packing of arguments in case of functions with no/multiple arguments
- predefined common functions:
id_,const,left,right,guard,first,secondcurry,uncurry,flip,ap,compose,split,case_,fplus,ftimes,fpower,fpower_left
- operator sections
- lazy expressions (suspended computations)
- printable function and lambda expressions
- evaluation tracing
- inductive and co-inductive types
Functor,fmapFix,fixcata(catamorphisms, folds)ana(anamorphims, unfolds)
Main classes:
Func, for composable, printable, and traceable functions with auto-(un)packing of arguments.OperatorSection, for operator sectionsLazy, for lazy expressions.
Not intended for industrial use:
- there are performance penalties in terms of memory and execution overhead
Notes:
- Type hints do not all verify (but it works). The Python type system is too limited (we need Higher-Kinded Types, HKTs).
- Binding strength of function combinators are as applied by Python, doesn't correspond to the theory.
Future work
- Applicatives and monads
Installation
pip install FuPy
Development (for developers)
- Build:
python -m build
- Test:
pytest
- Build documentation:
In
docs/make clean make html
- Upload to PyPI:
twine upload dist/*
Authors and acknowledgment
- Tom Verhoeff (Eindhoven University of Technology, Netherlands)
License
Project status
- Under development, but already usable
- Documentation:
- incomplete
- Sphinx version still has issues
- Test cases: incomplete
- Functionality:
- functions only print in mixed Math/Python notation
- level of detail in tracing cannot be selected
- limited form of laziness
- Issues
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
fupy-0.9.1.tar.gz
(28.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
fupy-0.9.1-py3-none-any.whl
(30.2 kB
view details)
File details
Details for the file fupy-0.9.1.tar.gz.
File metadata
- Download URL: fupy-0.9.1.tar.gz
- Upload date:
- Size: 28.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
919def89619a98abd3cad1afeee6e8c3aa7908b8d4040f81c0767facb7a971ac
|
|
| MD5 |
5ba0e243a5ad72147500ab3b7879a996
|
|
| BLAKE2b-256 |
49f910e841e3ea220cc2d66fc8affd9a62f985d6620b994a0c13dd9eeb5a2cdd
|
File details
Details for the file fupy-0.9.1-py3-none-any.whl.
File metadata
- Download URL: fupy-0.9.1-py3-none-any.whl
- Upload date:
- Size: 30.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a519a90347c1f06c1f3e075ef52e4c965e2849704e7ab1c3262908eae4a5e0da
|
|
| MD5 |
fe24d3e1682bf8ae4f3112c711b0e0a8
|
|
| BLAKE2b-256 |
55abc1e7753438bff96fbc16ac2a4ab21c4978dc915a780f84152a24ce981164
|