tags:

views:

189

answers:

1

Hi. I am new to Haskell, using Ghci.

I have a function, called three, that I want to write as

let three =  \x->(\y->(x(x(x y))))

OK, this works, but when I try

three (2+) 4

It does not work. Instead, I get some "cannot construct infinite type" error.

Please help me.

+2  A: 
ghci> let three = \x->(\y->(x(x(x y))))
ghci> three (2+) 4
10
ghci> three return "deconstructivist"

<interactive>:1:6:
    Occurs check: cannot construct the infinite type: t = m t
      Expected type: t
      Inferred type: m t
    In the first argument of 'three', namely 'return'
    In the expression: three return "deconstructivist"
ghci> :t three
three :: (t -> t) -> t -> t
ghci> :t return
return :: (Monad m) => a -> m a
  • The example you supplied of three (2+) 4, works! Better check that the examples you provide actually reproduce your problem.
  • As for with a different example, like the one above with return, the thing is that return results in a different type than the one given. If the type was the same, it would be infinite (and of kind * -> * -> * -> ...), which Haskell does not support.
yairchu