weird constraint

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

weird constraint

Dimitri DeFigueiredo
Could someone help me make sense of this Num constraint given by GHCi?
I was expecting to get:

inc . const :: Num a => a -> b -> a

rather than:

inc . const :: Num (b -> a) => a -> b -> a

Here's the transcript:


GHCi, version 8.6.3: http://www.haskell.org/ghc/  :? for help
Prelude> inc x = x + 1
Prelude> :t inc
inc :: Num a => a -> a
Prelude> :t const
const :: a -> b -> a
Prelude> :t inc . const
inc . const :: Num (b -> a) => a -> b -> a
Prelude>


Thanks,

Dimitri

--
2E45 D376 A744 C671 5100 A261 210B 8461 0FB0 CA1F


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: weird constraint

Sylvain Henry-2
Remember that a -> b -> a is equivalent to a -> (b -> a)

So: (forall a. Num a => a -> a) . (a -> (b -> a))
Becomes: (Num (b -> a). (b -> a) -> (b -> a)) . (a -> (b -> a))
Then: Num (b -> a). a -> (b -> a)
Finally: Num (b -> a). a -> b -> a


On 16/01/2019 15:52, Dimitri DeFigueiredo wrote:

> Could someone help me make sense of this Num constraint given by GHCi?
> I was expecting to get:
>
> inc . const :: Num a => a -> b -> a
>
> rather than:
>
> inc . const :: Num (b -> a) => a -> b -> a
>
> Here's the transcript:
>
>
> GHCi, version 8.6.3: http://www.haskell.org/ghc/  :? for help
> Prelude> inc x = x + 1
> Prelude> :t inc
> inc :: Num a => a -> a
> Prelude> :t const
> const :: a -> b -> a
> Prelude> :t inc . const
> inc . const :: Num (b -> a) => a -> b -> a
> Prelude>
>
>
> Thanks,
>
> Dimitri
>
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: weird constraint

Yitzchak Gale
On 16/01/2019 15:52, Dimitri DeFigueiredo wrote:
>> ...I was expecting to get:
>> inc . const :: Num a => a -> b -> a
>>
>> Prelude> inc x = x + 1

On Wed, Jan 16, 2019 at 5:06 PM Sylvain Henry <[hidden email]> wrote:
> Remember that a -> b -> a is equivalent to a -> (b -> a)...

To augment Sylvain's explanation: The upshot of this unexpected type -
which would almost certainly lead to a type error in any real program -
is that you probably want
const . inc
rather than
inc . const

-Yitz
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners