> This is what I've been trying:
> 
> always :: (a -> a) -> a -> a
> always x = (\y -> x)

Your function implementation is correct, but the type is wrong. Try
this:

always :: a -> b -> a

Or, just use the function "const", from the Prelude. :-)

The type system can be very handy when learning Haskell. If you think
you have the correct implementation but can't work out the type, just
start up an interpreter and ask it for the inferred type. For example:

Prelude> let always x _ = x
Prelude> :t always
always :: t -> t1 -> t

Once you have the type, ask Hoogle if the function already exists:

http://haskell.org/hoogle/?q=t+-%3E+t1+-%3E+t

And there is "const" at the top of the results. :-)


_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to