Order matters when type-checking
When I say
{-# LANGUAGE RankNTypes #-}
module Bug where
foo True = (\x -> x) :: (forall a. a -> a) -> forall b. b -> b
foo False = \y -> y
the module compiles. But when I say
{-# LANGUAGE RankNTypes #-}
module Bug where
foo False = \y -> y
foo True = (\x -> x) :: (forall a. a -> a) -> forall b. b -> b
it doesn't, failing with
Bug.hs:6:13:
Couldn't match type ‘b0 -> b0’ with ‘forall a. a -> a’
Expected type: (forall a. a -> a) -> forall a. a -> a
Actual type: (forall a. a -> a) -> b0 -> b0
In the expression:
(\ x -> x) :: (forall a. a -> a) -> forall b. b -> b
In an equation for ‘foo’:
foo True = (\ x -> x) :: (forall a. a -> a) -> forall b. b -> b
I believe this behavior stems from the special case in tcMonoBinds
, for non-recursive functions without a type signature. I believe the bug would be fixed if that function also checks to make sure that there is precisely one clause to the function. Do you agree?
Trac metadata
Trac field | Value |
---|---|
Version | 7.10.1 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | |
Operating system | |
Architecture |