August, 2009 [Reset]
Type Mess
Today I bumped into Haskell's "Monomorphism Restriction", which essentially requires that you provide explicit type information on parameters that are overloaded. It appears that GHC/i aggressively tries to avoid producing this error, which can lead to some strange behavior. For instance, f is a function to show and then print something:

f = putStrLn . show

Loaded into GHCi in a file by itself will produce the MR error. However:

f = putStrLn . show

f [1, 2]

Does not. If you query the type of f, it reports f :: [Integer] -> IO (). It's inferred that f takes a list of Integers from our function call, which is understandable but not quite as general as we'd intented f to be. If we add an another call to display a string:

f = putStrLn . show

f [1, 2]
f "ab"

We receive a unhelpful type error about the value of "1". I was scratching my head for awhile until I checked the type of my helper function.

The solution? Explicitly add the type signature:

f :: Show a => a -> IO ()

f = putStrLn . show
8/29/2009 9:26 PM
1
 
Waiting
IMG_3413
IMG_3415

Krista is a few weeks away from her due date with all the requisite aches but with noticeably more energy than just a few weeks ago. I think I'm ready for baby to arrive, but that's easy to say in the calm before the storm.

Above are from a fun day out in Stillwater.
8/29/2009 7:52 PM