Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/acorrenson/pym-s
Python with a sweet functionnal taste
https://github.com/acorrenson/pym-s
functional-programming ocaml python transpiler typedef
Last synced: 19 days ago
JSON representation
Python with a sweet functionnal taste
- Host: GitHub
- URL: https://github.com/acorrenson/pym-s
- Owner: acorrenson
- License: mit
- Created: 2019-08-16T02:55:44.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-11T13:26:04.000Z (about 5 years ago)
- Last Synced: 2024-11-20T11:54:26.211Z (3 months ago)
- Topics: functional-programming, ocaml, python, transpiler, typedef
- Language: OCaml
- Size: 367 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Pym-s
> Python with a sweet functionnal taste
Pyms is a transpiler. It produces clean and reliable python modules from OCaml-like type definitions. Pym-s is mainly designed to make symbolic manipulations easier and safer in python3.
Python modules generated with Pym-s are annotated according to the [PEP 484](https://www.python.org/dev/peps/pep-0484/) making them well suited for use with modern linters or type checkers such as [pyre](https://pyre-check.org/). Future versions of Pym-s will also include an option to generate dynamic type verification.
**Example** :
```python
# bintree.pymstypedef binary_tree =
| Node of int * binary_tree * binary_tree
| Leaf of int
``````python
# main.pyfrom bintree import *
def count_leafs(bt : binary_tree):
if isinstance(bt, Leaf):
return 1
else:
_, child1, child2 = bt
return count_leafs(child1) + count_leafs(child2)# outputs 2
print(count_leafs(Node(0, Leaf(1), Leaf(2))))
```The preceding exemple need to be compiled down to pure python prior to execution :
```
$ pyms -i bintree.pyms -o bintree.py
$ python3 main.py
```# Install
Installing Pyms requires opam and a working ocaml environnement. While waiting for Pyms to be published on Opam, it is still possible to install it easily.
To install ocaml and opam, please visit [this link](https://ocaml.org/docs/install.html)
## If you just have opam installed :
```
git clone [email protected]:jdrprod/Pym-s.git
cd Pym-s
opam pin .
opam install .
```## If you already use dune :
```
git clone [email protected]:jdrprod/Pym-s.git
cd Pym-s
dune build @install
dune install
```