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
Empty
type without valuesUnit
type with valueunit
Either[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 repeated composition, also written with a superscript
- auto (un)packing of arguments in case of functions with no/multiple arguments
- predefined common functions:
id_
,const
,left
,right
,guard
,first
,second
curry
,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
,fmap
Fix
,fix
cata
(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.8.1.tar.gz
(23.6 kB
view details)
Built Distribution
FuPy-0.8.1-py3-none-any.whl
(25.4 kB
view details)
File details
Details for the file fupy-0.8.1.tar.gz
.
File metadata
- Download URL: fupy-0.8.1.tar.gz
- Upload date:
- Size: 23.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f397ae14640847a0d1e09a22c7b17e68ff5ea0751ecbd2124d815ee69d9aa2b |
|
MD5 | bb7b646839308d15bab03dd0ac66bb46 |
|
BLAKE2b-256 | 38104bb1719988314730a0bf8fa63757f617bde1b7f48a9618c56299e768b3a9 |
File details
Details for the file FuPy-0.8.1-py3-none-any.whl
.
File metadata
- Download URL: FuPy-0.8.1-py3-none-any.whl
- Upload date:
- Size: 25.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.0 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1270699f3b3103a60a1f4445bcbf1971fd7c8695276158301d392f44c79e807e |
|
MD5 | 3fabbfb1bec890c730e94a3640d02f40 |
|
BLAKE2b-256 | e04de7e5910205e7d23a4cbd16d2cb0de49c55b8d1e4e385f564f25506702e86 |