Finally got around to recording this one. Here's the String Calculator Kata in Haskell using a bit of REPL-based TDD through ghci.
The final refactoring felt like a bit of a stretch. I'm still not sure how far to go when point-free style seems to be just in reach. In this case, using a pair for the delimiter and the calculation string allowed me to avoid passing the input string as a parameter in the middle of a train of function compositions. I wonder whether there is a name for this technique?
If you hoogle the type signature for converting a function with 2 parameters into a function with one 2-tuple parameter, you find "uncurry".
(a -> b -> c) -> ((a,b) -> c)
http://haskell.org/hoogle/?hoogle=(a+-%3E+b+-%3E+c)+-%3E+((a,+b)+-%3E+c)
let add x y = x + y
:t add
add :: (Num a) => a -> a -> a
:t uncurry add
uncurry add :: (Num a) => (a,a) -> a
Tupling up extra data in the return type is a little different, but sounds a lot like the Reader monad or State monad.
Posted by: Dan Burton | January 04, 2011 at 07:35 AM
Two other functions of note -- Data.List.isPrefixOf, and Control.Arrow.&&&. The latter lets you write `(delimiter &&& body) text` which helps the pointfreeness.
Posted by: sclv | January 04, 2011 at 09:18 AM
For anyone curious: the wisely-chosen music is by Recoil. :)
Posted by: Jeremy | January 04, 2011 at 09:42 AM
Great music. I don't understand anything in Haskell :)
Posted by: Jiggaboo | March 12, 2011 at 12:31 PM
I watch it from time to time just to listen to the great music.
Posted by: Karep | December 16, 2011 at 08:01 AM