[Haskell-cafe] Can't figure out how to "show" for type "Int -> (Int, Int)"

Tom Titchener Tom.Titchener at microsoft.com
Thu Jan 11 09:37:17 EST 2007


Typing up and running (via Hugs) the examples in Wadler's excellent "Monads for functional programming" (here: http://homepages.inf.ed.ac.uk/wadler/papers/marktoberdorf/baastad.pdf) I hit the inevitable "show" function error:

ERROR - Cannot find "show" function for:
*** Expression : eval answer
*** Of type    : Int -> (Int,Int)

I can find lots of nice text about extending data for "show" (including the miraculous "Deriving") but... I'm showing my Haskell newbie roots by utterly failing to understand how to do this of a "higher-order" type (my best guess for the right term for the type Int -> (Int, Int)).

It'd be a big help if somebody could tell me either:


a)      It's obvious, you moron, just <insert Haskell code here>

or


b)      It's impossible, you moron, you're trying to violate the <insert Haskell rule here>

Here' my code:

data Term = Con Int | Div Term Term
type M a = State -> (a, State) -- higher-order type, e.g. function type
type State = Int -- type synonym
eval :: Term -> M Int
eval (Con a) x = (a, x)
eval (Div t u) x = let (a, y) = eval t x in
                    let (b, z) = eval u y in
                    (a `div` b, z + 1)
answer, error :: Term
answer = (Div(Div(Con 1972)(Con 2))(Con 23))
error = (Div(Con 1)(Con 0))

I get the "ERROR" message when I type "eval answer" at the Hugs prompt.

Thanks!

Tom Titchener

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070111/69d6eb09/attachment.htm


More information about the Haskell-Cafe mailing list