22 May 2015
I just finished attending the excellent Brisbane YOW! Lambda Jam. One of the really useful things I learned from Tony Morris was “Hole Driven Development” for Haskell - basically using the type system to help you write a function.
Firstly, when writing a function, you can use placeholders that will allow code to compile (without producing error messages) while you’re working on other parts. The two placeholders are:
error "todo" (or any string) undefined
The “hole driven” part involves using the underscore to get the compiler to print types:
_undefined _x _foo
For example if I used
_x then re-loaded my code in ghci, I would get
Found hole ‘_x’ with type: a ... g2 :: a -> b (bound at GetSetLens.hs:312:31) s2 :: a -> b -> a (bound at GetSetLens.hs:312:28) g1 :: b -> c (bound at GetSetLens.hs:312:18) s1 :: b -> c -> b (bound at GetSetLens.hs:312:15)
Showing me that where I had
_x a type
a was expected, and that I already
g2,s2,g1,s1 that consume and produce (curry) given types.
See also the post and video by Matthew Brecknell Hole-driven Haskell.comments powered by Disqus