[Haskell-cafe] On to applicative

David Menendez dave at zednenem.com
Thu Sep 2 11:08:17 EDT 2010


On Thu, Sep 2, 2010 at 10:45 AM, michael rice <nowgate at yahoo.com> wrote:

>
> 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 <dave at zednenem.com>
<http://www.eyrie.org/~zednenem/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20100902/73886db0/attachment.html


More information about the Haskell-Cafe mailing list