Skip to content
rpeszek edited this page May 20, 2019 · 35 revisions

IdrisTddNotes

There is a small portion of Java developers who dream about programming in Scala.
There is a sizable portion of Scala developers who dream about programming in Haskell.
All Haskell programmers want to program in Idris.

;)

Notes from reading Type Driven Development with Idris.
This Wiki contains test and example programs compiled to markdown.

These notes compare Idris code in the book against Haskell. My goal is to write Haskell code very closely mimicking Idris to see the value added by dependent types.

This comparison is somewhat unfair to Haskell as I am converting examples from a book about Idris and I try to keep Haskell code as close to Idris as possible.
Idris is playing on its own turf so to speak.
The other reasons for the unfairness is a risky assumption that I know how to 'haskell' :), or that I know enough of it to make the comparison meaningful.

This work is mostly done, some cleanup work is still in progress
I also started working on Scala IdrisTddScalaNotes version of these notes in a separate project. This page links to equivalent code in in that project.

TOC

Part 1

Part 2

I used `GHC.TypeLits` at the beginning but decided to abandon them from here on
(see [WorkingWithTypeLits.hs in my LC2019 presentation](https://github.com/rpeszek/present-proofs-lc19/blob/master/src/Present/WorkingWithTypeLits.hs))
`singletons` are used (more and more) from here on
  • Part2_Sec8_3_deceq - Dec/DecEq using Nat and MyPair, exactLength example

  • Part2_Sec9_1_elem - type safe elem functions

  • Part2_Sec9_2_hangman - hangman game

  • Part2_Sez10_1_views - ListLast, SplitList, TakeN views, reverse, mergeSort, groupByN, and halves examples. This note also uses ``-XViewPatterns which is similar to Idris'with`. I am not using it elsewhere because it does not play well with `-fwarn-incomplete-patterns`.

  • Part2_Sez10_2a_snoc - reverse using SnocList GADT - seems impossible to match linear cost of Idris code!

    • Part2.Sez10_2aVect.hs implements reverse Vect n a with SnocVect mimicking the type level code for list. I had to use :~~: instead of :~: as type equality. This is not a linear cost algorithm.
    • Part2.Sez10_2aVect2.hs implements a more straightforward SnocVect. No SVect, VAppend type families, etc are used. This version has linear cost if proofs cost is ignored as in ProofPerformance.
  • Part2_Sez10_2b - isSuffix using SnocList GADT

    • Sez10_2e.idr (Exercises from 10.2) use advanced views and have linear cost. I can only see slower Haskell representations of these.
  • Part2_Sez10_3_hiding - attempt to mimic ShapeView API

Part 3

  • Sec14a_DoorJam - I have skipped converting 'Door' state machine example to Haskell.
  • Part3_Sec14b_ATM - ATM protocol converted to Haskell. This program implements the very interesting and powerful monad-like DSL with safe state transitions. Unfortunately, I had to use unsafeCoerce converting the >>= to IO.
  • Part3_Sec15a_ProcessLib - Dependently typed concurrent protocol library.
    • Concurrent programming is very error prone. I suffered quite a bit implementing version of Idris primitives here
  • Part3_Sec15b_ProcessList - Example using the above library

Play

Set of notes and not book related experiments.

Idris goodness

(TODO)

Some interesting links

https://personal.cis.strath.ac.uk/conor.mcbride/pub/hasochism.pdf
https://blog.jle.im/entry/introduction-to-singletons-1.html
https://blog.jle.im/entry/introduction-to-singletons-2.html
https://typesandkinds.wordpress.com/2012/12/01/decidable-propositional-equality-in-haskell/

Environment

Currently using ghc 8.2.2 and Idris 1.2.0

FYI about stack/ghc To play with newer version of TypeLits and singletons I have upped ghc/stack to lts-11.5 / 8.2.2. This is known to be a problem for older version of stack. If your stack came with ghc distribution, stack update may not work. I had to delete stack symbolic link in /usr/local/bin and reinstall it.

Idris instructions

  • To compile run make from root directory
  • To run repl navigate to src directory first and start repl there (idris repl)