coconut-prelude
coconut-prelude copied to clipboard
An implementation of Haskell's Prelude in Python using Coconut.
coconut-prelude
An implementation of Haskell's Prelude in Python 3.6+ using Coconut.
Installation
pip install coconut-prelude
Usage
To use coconut-prelude
, just
from prelude import *
which should make all the standard Haskell built-ins available to you. The only exceptions are Haskell operators and Haskell built-ins that use reserved names in Python, which have been given the following names:
fmapConst = (<$)
ap = (<*>)
seqAr = (*>)
seqAl = (<*)
bind = (>>=)
seqM = (>>)
bindFrom = (=<<)
dot = (.)
apply = ($)
cbv = ($!)
cons = (:)
chain = (++)
at = (!!)
not_ = not
return_ = return
and_ = and
or_ = or
break_ = break
import Data.Ratio
over = (%)
Furthermore, the following special functions are made available to mimic certain Haskell syntaxes, with information on each accessible via help(func)
:
of
do
asIO
unIO
derivingOrd
derivingBoundedEnum
definesBind
definesReturn
Additionally, it is highly recommended, though fully optional, that coconut-prelude
be used with MyPy to enable static type-checking and Coconut to enable easier usage of functional programming constructs, such as those used to define the prelude in the first place.
Even if not using Coconut, however, to get MyPy working with coconut-prelude
will require you to follow the instructions here to generate the necessary stub files and add them to your MYPYPATH
.
For additional documentation, either read the source code or view the auto-generated documentation.