• Stars
    star
    124
  • Rank 286,621 (Top 6 %)
  • Language
    Haskell
  • License
    Other
  • Created over 9 years ago
  • Updated almost 7 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Python backend for Idris (generates Python source, not bytecode).

Python back-end for Idris

Goodies

  • expressions in tail positions return directly
  • if-elif sequences optimised
    • not doing comparison if it's clear which branch to take
    • single-branch trees turned into assertions (ignore them with python -O) and flattened
  • tail-call optimisation (does not work for mutual recursion)
    • There is a full TCO branch using trampolines but it consumes more stack frames, thus making non-tail-recursive programs crash earlier so it's not merged into master.
    • Another full TCO branch preserves the number of stack frames but it's even slower.
  • principled codegen monad makes it easy to compile from DExp
  • allows typechecked use of Python libraries (example)
    • thanks to signatures for Python objects (example).
    • fully dependent type signatures are supported (example), including arguments with defaults
  • allows duck typing (example)
  • error reflection yields messages like:
    • Field "gets" does not exist in object signature "Session"
    • Iterable Int is not mixed into signature "Response"
  • foreach -- higher-order FFI :)
  • big case trees compiled specially
    • constructor-cases to binary search on tags
      • seems to bring down pythag 100 from 5.5 secs to 3.5 secs, probably because of APPLY0
    • constant-cases to dictionary lookups
      • a bit wasteful (evaluates too much in non-trivial cases) -- but apparently easy to do
  • comments in the generated Python code show the meaning of low-level code
    • constructor names next to numeric constructor tags
    • readable names next to mangled names
  • exceptions (no hierarchy yet, though) (example)
  • threading, message passing and forkPIO (example)
  • Just x compiles to x, Nothing compiles to None
    • this gives choice to FFI authors to say whether they care about None by having FFI functions take/return either bare values or maybe-values.
  • calling Idris from Python (exports, usage)

Observations

  • it turns out that using Text to represent generated code in the prettyprinter (branches/text) is not that much win
    • strict Text seems to be a bit slower than String
    • lazy Text seems to be about as fast as String
    • String is the simplest

Install using Stack

First, the codegen:

$ stack build

Then, the library:

$ cd lib
$ stack exec idris -- --install python.ipkg

Some Python libraries for the example programs:

$ pip install requests bs4 numpy

Running the Examples

Compile the example

$ cd examples/
$ stack exec idris -- example.idr -p python --codegen python -o example.py

Install using Cabal

First, the codegen:

$ cabal sandbox init --sandbox $IDRIS_PATH/.cabal-sandbox
$ cabal configure && cabal build

Then, the library:

$ cd lib
$ idris --install python.ipkg

Some Python libraries for the example programs:

$ pip install requests bs4 numpy

Finally, set up your path appropriately:

$ export PATH="$PATH:$IDRIS_PATH/.cabal-sandbox/bin/"

Running the Examples

Compile the example

$ cd examples/
$ idris example.idr -p python --codegen python -o example.py

Calling Python from Idris

$ python example.py
Idris has got the following exciting features:
1. Full dependent types with dependent pattern matching
2. Simple foreign function interface (to C)
3. Compiler-supported interactive editing: the compiler helps you write code using the types
4. where clauses, with rule, simple case expressions, pattern matching let and lambda bindings
5. Dependent records with projection and update
6. Type classes
7. Type-driven overloading resolution
8. do notation and idiom brackets
9. Indentation significant syntax
10. Extensible syntax
11. Cumulative universes
12. Totality checking
13. Hugs style interactive environment
Total number of features: 13

thread A starting
thread B starting
thread A done
thread B done
thread A says 9121
thread B says 9121

And now, let's fail!
  -> (1) everything's fine: [Errno 13] Permission denied: '/root/hello'
  -> (2) everything's fine: [Errno 13] Permission denied: '/root/hello'

Calling Idris from Python

>>> import example
>>> example.greet()
Hello world!

More Repositories

1

lightyear

Parser combinators for Idris
Idris
236
star
2

rarcrack

[unofficial fork] RAR bruteforce cracker
C
97
star
3

pmtu

Path MTU discovery tool
Python
34
star
4

itt-idris

ITT: quantified dependent calculus with inference of all modalities, implemented in Idris 2
Idris
23
star
5

idris-ocaml

OCaml back end for Idris
Haskell
22
star
6

bibdris

BibTeX database management in Idris
Idris
18
star
7

idris-data-frame

Data frames for Idris 2
Idris
18
star
8

ttstar

Dependently typed core calculus with erasure
Idris
17
star
9

itt

Tiny dependent calculus with inference of irrelevance and erasure
Haskell
15
star
10

text

Text framework for Idris
Idris
13
star
11

idris-benchmarks

Some benchmarks for Idris
Idris
11
star
12

idris2-mlf

Malfunction backend for Idris 2
Idris
11
star
13

idris-bytes

FFI-based byte buffers for Idris
Idris
11
star
14

keychain-bruteforce

Bruteforce master passwords of the MAC OS X password manager.
Python
8
star
15

idris-scheme

Scheme codegen for Idris
Haskell
6
star
16

scan-eSCL

Scan from eSCL-compatible scanners
Python
4
star
17

deconvolution

A deconvolution algorithm
MATLAB
4
star
18

meshub

A lightweight mesh VPN
Python
3
star
19

simple-prolog

A simple Prolog implementation in Haskell
Haskell
3
star
20

macro-pp

Universal macro preprocessor
Haskell
3
star
21

wireplay

[MIRROR] A minimalist approach to replay pcap-dumped TCP sessions.
C
2
star
22

idris2-perf

Various benchmarks
Idris
2
star
23

hackup

Backup system written in Haskell
Haskell
2
star
24

ever-to-excel

Compile a Scheme-like language into a spreadsheet
Haskell
2
star
25

globusator

Globe stripe generator
Perl
2
star
26

hilite

Terminal output highlighter
Perl
1
star
27

buslittles

Watch subtitles on laptop while film is playing on TV
CoffeeScript
1
star
28

qanachem

Anaglyph Chemistry
C++
1
star
29

stacker

Astrophotography stacker
C++
1
star
30

lamtc

Simple Prolog type checker
Prolog
1
star
31

wlist

iw scan parser
Haskell
1
star
32

jpg-recover

Recover JPEG/CR2 files from raw bytes.
C
1
star
33

idris-ttstar

TTstar backend for Idris
Haskell
1
star
34

excomp

A certified compiler of exceptions from my thesis (Agda)
JavaScript
1
star
35

ecomp

A simple certified expression compiler (Coq)
Verilog
1
star
36

ledger-vim

Feature-free vim plugin for ledger files
Vim Script
1
star
37

anamovie

Create anaglyph movies from stereomovies
C
1
star
38

dictpress

Preprocess wordlists before compression
C
1
star
39

trees

Even-odd trees from plain lists, structurally:
Haskell
1
star
40

ofca

OFCA Free Command Analyzer
C++
1
star
41

leveler

HDR to LDR leveler
C++
1
star
42

pastemath

A math pastebin (pastemath.functor.sk)
JavaScript
1
star