[Haskell-cafe] need help with understanding expression
Ramana Kumar
Ramana.Kumar at cl.cam.ac.uk
Fri Nov 16 09:07:42 CET 2012
On Fri, Nov 16, 2012 at 8:00 AM, Daryoush Mehrtash <dmehrtash at gmail.com>wrote:
> Sorry wrong paste
>
> Prelude> :t 3 2
> 3 2 :: (Num a, Num (a -> t)) => t
>
It means that 2 has type a (which must be in the Num class), 3 has type (a
-> t) (which also must be in the Num class), and the type of (3 2) is
therefore t.
When you apply one expression to another, the first must have function
type, and the second must have the type of the domain of the function,
hence the a -> t and a.
Furthermore, the numeric literals are always interpreted as being in the
Num class.
I haven't been able to find any good introduction to numeric literals and
the Num class with quick search, so if anyone else on list can point us to
one (if it exists) that would be great.
>
>
> What does the type mean in plain english?
>
> Daryoush
>
> On Fri, Nov 16, 2012 at 12:00 AM, Daryoush Mehrtash <dmehrtash at gmail.com>wrote:
>
>> Yes, same problem, and again I have no idea how to read the type
>>
>> Prelude> :t max. 3 2
>> max. 3 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b
>>
>>
>> What does the type mean in plain english?
>>
>> Daryoush
>>
>> On Thu, Nov 15, 2012 at 11:56 PM, Ramana Kumar <Ramana.Kumar at cl.cam.ac.uk
>> > wrote:
>>
>>> Another experiment may be revealing:
>>>
>>> :t 3 2
>>>
>>>
>>>
>>> On Fri, Nov 16, 2012 at 7:46 AM, Daryoush Mehrtash <dmehrtash at gmail.com>wrote:
>>>
>>>> I see the point with :t (.) that
>>>>
>>>> max.(+1) 2 2
>>>>
>>>> is the same as
>>>>
>>>> max. 3 2
>>>>
>>>> Which is not what I want.
>>>>
>>>> But I have no idea what the type signature of this expression mean now
>>>>
>>>> Prelude> :t max. 3 2
>>>> max. 3 2 :: (Ord b, Num a1, Num (a1 -> a -> b)) => a -> b -> b
>>>>
>>>> Any idea?
>>>>
>>>> Daryoush
>>>>
>>>>
>>>> On Thu, Nov 15, 2012 at 11:19 PM, Ramana Kumar <
>>>> Ramana.Kumar at cl.cam.ac.uk> wrote:
>>>>
>>>>> 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
>>>>>>
>>>>>>
>>>>>
>>>>
>>>>
>>>> --
>>>> Daryoush
>>>>
>>>> Weblog: http://onfp.blogspot.com/
>>>>
>>>
>>>
>>
>>
>> --
>> Daryoush
>>
>> Weblog: http://onfp.blogspot.com/
>>
>
>
>
> --
> Daryoush
>
> Weblog: http://onfp.blogspot.com/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20121116/acbbcab1/attachment.htm>
More information about the Haskell-Cafe
mailing list