Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Pythas Python package Documentation Status

Import Haskell modules as if they were Python modules. If an imported name does not exist as Python module/package, Pythas will traverse the specified subdirectory below your cwd to look for a matching Haskell file. If one is found it is imported just as if it was a Python module.

If you have a file Example.hs like in the example directory, it will be imported and can be used like such:

>>>import pythas
>>>import example.example as e
>>>e.hello()
Hello from Haskell!

You can also just from * import. Try:

>>>from example.example import multisin
>>>from math import pi
>>>multisin(2,pi)
2.4492935982947064e-16

and you'll see: It doesn't stop at invoking side-effects.

Sequences

Python Sequences can be passed as linked lists or as arrays. Depending on which flavour of programming you want to embrace. Currently for speed and space reasons arrays are used by the backend, but it should be no problem to change that for those hardcore FP nerds stuck in Haskell-land. Try things like:

>>>from example.example import mapQuarter
>>>mapQuarter(range(1000,5000,1000))
[250.0, 500.0, 750.0, 1000.0]

While in Haskell lists have to be used, in Python any kind of sequence can be handed over. Needless to say, varying types won't be supported.

Tuples

You can use tuples to pack results of different types into a single one. It is no problem to nest them and lists or vice versa. Checkout test.hs.Test.hs to see what Pythas is (successfully) tested for.

>>>from example.example import tuple, hsnd
>>>tuple()
(1,"a")
>>>hsnd((1,2))
2

Requirements

Please make sure that GHC is located in your $PATH. Pythas requires at least GHC version 8.0.2. It defaults to using stack ghc. To check if your GHC version is compatible run:

$ stack ghc -- --version

or without stack installed:

$ ghc --version

Pythas is written with compatibility and ease of use in mind. All libraries used in the Haskell backend are contained in the standard installation of GHC. No requirements exist on the Pythonic side of life.

Install

Pythas can be installed using pip. Run the following command to install and compile it at once:

$ pip install pythas && python -c "import pythas"

or from source:

$ git clone https://github.com/pinselimo/Pythas.git && cd Pythas
$ pip install . && python -c "import pythas"

Constraints

Only Python versions 3.7 and up are supported. Unfortunately, only [PEP 562] introduced __getattr__ for modules. This renders the level of abstraction Pythas aims for impossible on lower Python versions.

Only functions having their type declared will be imported. You can handle the export of the function yourself by adding a foreign export ccall for the function, otherwise Pythas will do that for you. To exclude a function just omit the functions type. Functions of types that are not supported won't get exported either.

All Haskell constants in the IO monad are imported as functions. Due to lists being turned into CArrays even constant lists must be called like a function without arguments:

>>>from example.example import someConstant, haskellList
>>>someConstant
63
>>>haskellList()
[63]

The same is true for tuples which are turned into or CTuple{x}s.

Pythas enforces the file naming scheme of Haskell for .hs files as does the GHC! This is primarily due to GHC failing to find the imported module at compile time. Thus, we fail early and raise a ModuleNotFoundError.

Docs

Contributing

Meaningful contributions are always welcome, please refer to CONTRIBUTING.md for details.

Testing

The sub-repositories Pythas incorporates all ship their own testing facilities. Testing of the pythas package itself therefore focuses on the main functionality and user interface. It incorporates some unit tests and property based testing mostly focusing on ensuring the interface does not alter any data. To execute the tests in bulk just move to the project root and execute:

$ pytest

License

The Software in this repository is licensed under the LGPLv3 License. See COPYING.LESSER file for details.

Pythas  Copyright (C) 2020  Simon Plakolb
This program comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see COPYING and COPYING.LESSER.

Metadata

Release files for pythas 0.1b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pythas 0.1b1
File Size Uploaded
pythas-0.1b1.tar.gz 66.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pythas 0.1b1
File Interpreter ABI Platform
pythas-0.1b1-py3-none-any.whl Python 3 none any Details

Total release size: 140.9 kB

Release files / pythas-0.1b1.tar.gz

Download URL pythas-0.1b1.tar.gz
Size 66.1 kB
Tags Source
SHA-256 checksum
How to use checksums
aaac0691f5306db8dfaf013cbabe2c80ecc2bbe00321f89536a9b7692f554ab6
BLAKE2b-256 checksum
How to use checksums
0b1b2980b22b9cab5eace023c2f26e683358e5dac58a39cfd612e258ec166b96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release files / pythas-0.1b1-py3-none-any.whl

Download URL pythas-0.1b1-py3-none-any.whl
Size 74.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
000675bbb2cee54b7c4e45e1c2c3d1f78fe35924f10f0ae201b18d42c3f437ca
BLAKE2b-256 checksum
How to use checksums
8a380b641d52f8c3af65f44baed47fa00a0d281dd1e53f7e81571997cd8cd025
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/3.9.0 pkginfo/1.5.0.1 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.44.1 CPython/3.7.7

Release history Release notifications | RSS feed

This release

0.1b1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page