Replacing => in place of -> in function type signa

2020-08-24 04:41发布

问题:

I just observed that if instead of ->, I write => in the type signature definition of a function, it doesn't result in an compile time error. Example code:

mysum :: Num a => [a] => a -- Notice => after the list [a]
mysum [] = 0
mysum (x:xs) = x + mysum xs

Why does this happen ? And is there a way to avoid this ?

Compiler Used: GHC 7.6.2

Update: Successful compilation in ideone.

回答1:

This is a bug in GHC 7.6.2. You should try it in the most recent compiler and if it still doesn't give an error there, then you should file a bug report.

Actually, I think this bug is already known and fixed in GHC 7.8.



回答2:

This seems to be fixed in 7.8.2

foo.hs:1:19:
    Expected a constraint, but ‘[a]’ has kind ‘*’
    In the type signature for ‘mysum’: mysum :: Num a => [a] => a

I would assume it's just a bug specific to 7.6.x.



标签: haskell