
On Thu, Sep 2, 2010 at 10:45 AM, michael rice
Can you think of a situation for
\x -> f x or \x y z -> x + ord y - head z
that would require x (y z) to have their type(s) declared (ala Pascal), or is it always inferred by what appears to the right of "->"?
I think Haskell 98 can always infer the type of an anonymous function. There are some extensions involving more advanced types that can't be inferred, but you don't need to worry about them yet.
I guess what I'm asking is can an anonymous function be given a type signature?
Sure. Just write (\x -> x + 1) :: Int -> Int. (The parentheses are
important. Without them, the type signature is given to the function body.)
I don't think I've ever needed to give a type for an anonymous function,
though. Generally, the context where the function is being used is
sufficient.
--
Dave Menendez