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.2.tar.gz
(24.8 kB
view details)
Built Distribution
FuPy-0.8.2-py3-none-any.whl
(26.4 kB
view details)
File details
Details for the file fupy-0.8.2.tar.gz
.
File metadata
- Download URL: fupy-0.8.2.tar.gz
- Upload date:
- Size: 24.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98d04f5d636e8c22d5ca6061938f01fa1cfb0584b2659c4e21681d65a5e0f82e |
|
MD5 | 4c15807d7f5b35651f5b8669aba19a84 |
|
BLAKE2b-256 | 1614b7bef9e9d626f517790cb69cb1a001a008becfb70e35258efad0cc426f0f |
File details
Details for the file FuPy-0.8.2-py3-none-any.whl
.
File metadata
- Download URL: FuPy-0.8.2-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8e9cd40aacbc33d604bc6b761d1c49203c6602eba0a3f77197fdd858d55e98a0 |
|
MD5 | 7c4e6953427a26f06491511713b1e85f |
|
BLAKE2b-256 | 9ed8586865ea433667a25736165c93f4506db9f4c106efe7f69e6daf608bba7f |