[Haskell-cafe] need help with understanding expression

Ramana Kumar Ramana.Kumar at cl.cam.ac.uk
Fri Nov 16 08:19:31 CET 2012


Hi Daryoush,

I recommend you try these experiments first, and then reply back if you're
still confused.

:t max

:t (+1)

:t max . (+1)

:t (+1) 2

:t (.)


On Fri, Nov 16, 2012 at 7:10 AM, Daryoush Mehrtash <dmehrtash at gmail.com>wrote:

> I am having hard time understanding how removing the  outer parenthesis in
>
> (max.(+1)) 2 2
>
> to
>
> max.(+1) 2 2
>
> changes the meaning of expression.
>
> My expectation was that "max.(+1) takes two numbers and returns the max as
> defined in the type:
>
> :t max.(+1)
> max.(+1) :: (Ord b, Num b) => b -> b -> b
>
>
>
> With parenthesis it does what I expect it to:
>
>
> Prelude> :t (max.(+1)) 2 2
> (max.(+1)) 2 2 :: (Ord b, Num b) => b
> Prelude>  (max.(+1)) 2 2
> 3
>
>
> But if I remove the parenthesis I get a beast that I have no idea what its
> type signature mean any more
>
> Prelude> :t (max.(+1)) 2 2
> (max.(+1)) 2 2 :: (Ord b, Num b) => b
> Prelude> :t max.(+1) 2 2
> max.(+1) 2 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b
>
>
> How did removal of parenthesis changed the meaning?      How do you
> interpret the type:  "(Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b"?
>
> Thanks
>
>
>
> --
> Daryoush
>
> Weblog:  http://onfp.blogspot.com/
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121116/d9ced963/attachment.htm>


More information about the Haskell-Cafe mailing list