Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/johannesmessner/pyskell
Abusing Python to make it feel like Haskell
https://github.com/johannesmessner/pyskell
Last synced: 3 months ago
JSON representation
Abusing Python to make it feel like Haskell
- Host: GitHub
- URL: https://github.com/johannesmessner/pyskell
- Owner: JohannesMessner
- Created: 2022-04-07T07:27:21.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-15T08:25:32.000Z (over 2 years ago)
- Last Synced: 2024-09-21T21:41:02.345Z (4 months ago)
- Language: Python
- Homepage:
- Size: 7.81 KB
- Stars: 10
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Stuck with Python but you actually want to use Haskell?
This is a silly package that (ab)uses Python operator overloading to reproduce beloved features from functional programming.
You can do:
**Currying**
```python
@curry
def f(a, b, c):
return a + b + c
f(1, 2, 3)
Out[0]: 6g = f << 1
g << 2 << 3
Out[1]: 6f << 1 << 2 <<< 3
Out[2]: 6
```**Infix Notation**
```python
@infix
def plus(a, b):
return a + b
1 |plus| 2
Out[0]: 3
```**Functional Programming!**
```python
@curry
def foldl(fn, x, xs):
return x if not xs else foldl << fn << (x |fn| xs[0]) << xs[1:]
sum = foldl << plus << 0sum([1, 2, 3])
Out[0]: 6
```## Installation
```pip install pyskell```
## Credit
Big **credit** goes to these guys:
- http://tomerfiliba.com/blog/Infix-Operators/
- https://sagnibak.github.io/blog/python-is-haskell-currying/