GithubHelp home page GithubHelp logo

suimong / coconut-prelude Goto Github PK

View Code? Open in Web Editor NEW

This project forked from evhub/coconut-prelude

0.0 1.0 0.0 937 KB

An implementation of Haskell's Prelude in Python using Coconut.

License: Apache License 2.0

Python 67.74% Makefile 0.17% HTML 32.10%

coconut-prelude's Introduction

coconut-prelude

An implementation of Haskell's Prelude in Python 3.8+ 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.

If you are using Coconut, you can also get access to actual custom Haskell operators with the code:

from prelude import operator $$  # apply ($)
from prelude import operator %%  # over (%)
from prelude import operator <$  # fmapConst
from prelude import operator <*>  # ap
from prelude import operator *>  # seqAr
from prelude import operator <*  # seqAl
from prelude import operator >>>=  # bind (>>=)
from prelude import operator >>>  # seqM (>>)
from prelude import operator =<<<  # bindFrom (=<<)
from prelude import operator ++  # chain
from prelude import operator !!  # at

For additional documentation, either read the source code or view the auto-generated documentation.

coconut-prelude's People

Contributors

evhub avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.