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

Henning Thielemann lemming at henning-thielemann.de
Thu Jan 11 09:40:38 EST 2007


On Thu, 11 Jan 2007, Tom Titchener wrote:

> 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.

'eval' requires two arguments, the second one is hidden in (M Int) which 
expands to (State -> (a, State)). That is, you must call

eval answer 42

or so.


More information about the Haskell-Cafe mailing list