Skip to main content

Functional Programming in Python, for Education

Project description

FuPy logo

FuPy: Functional Programming in Python, for Education

Pipeline Status Test Coverage Latest ReleasePyPI version License Documentation Status Python Versions

Overview

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 values
    • Unit type with value unit
    • Either[A, B] (disjoint sum) type
    • Both[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, 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 sections
  • Lazy, 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

MIT 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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fupy-0.9.1-py3-none-any.whl (30.2 kB view details)

Uploaded Python 3

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

Hashes for fupy-0.9.1.tar.gz
Algorithm Hash digest
SHA256 919def89619a98abd3cad1afeee6e8c3aa7908b8d4040f81c0767facb7a971ac
MD5 5ba0e243a5ad72147500ab3b7879a996
BLAKE2b-256 49f910e841e3ea220cc2d66fc8affd9a62f985d6620b994a0c13dd9eeb5a2cdd

See more details on using hashes here.

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

Hashes for fupy-0.9.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a519a90347c1f06c1f3e075ef52e4c965e2849704e7ab1c3262908eae4a5e0da
MD5 fe24d3e1682bf8ae4f3112c711b0e0a8
BLAKE2b-256 55abc1e7753438bff96fbc16ac2a4ab21c4978dc915a780f84152a24ce981164

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page