Skip to content

Latest commit

 

History

History
54 lines (36 loc) · 1.74 KB

File metadata and controls

54 lines (36 loc) · 1.74 KB

Calling PureScript From Python

You expect this is a large document? No, it's quite short:

  1. spago build
  2. python -c "from <your project name>.Main.pure import main;main()"

You can extract the generated Python package out, and encapsulate it as a standalone Python package, and upload to PyPI.

Module Path

Moreover, given such a PS module A.B:

module A.B(export1, export2) where
...

In Python, you can import export1 by

import <your project name>.A.B.pure as AB
AB.export1 # you got it

Calling Convention

This is also a reason why PureScript is pragmatic, because it uses the same calling convention as Python's.

It supports tail call optimizations, e.g., a purescript function like

f x y = x + y

can be used in Python in this way:

assert f(1)(2) == 3

Object Representation

Kind Given Definition PureScript Python
Datatype data S = S1 Int Number | S2 Text [S1 1 2.0, S2 "hello!"] ({"value0": 1, "value1": 2.0, ".t": S1}, {"value0": "hello!", ".t": S2})
Newtype newtype A = A Int A 1 1
Record No definition {a: 1, b: 2} {"a": 1, "b": 2}