Untouchable type variable (regression from 7.6)
Oleg says: what used to type check in GHC 7.4.1 (and I think
in 7.6.2, although I no longer have access to that version) fails in
GHC 7.8.2.
The following program type-checks with GHC 7.4.1 and GHC 7.8.2:
```
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
module T where
foo :: (forall f g. (Functor f) => f a -> f b) -> [a] -> [b]
-- foo :: (forall f g. (Functor f, g ~ f) => g a -> g b) -> [a] -> [b]
foo tr x = tr x
t = foo (fmap not) [True]
```
The following code (which differs only in the signature of foo)
```
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeFamilies #-}
module T where
-- foo :: (forall f g. (Functor f) => f a -> f b) -> [a] -> [b]
foo :: (forall f g. (Functor f, g ~ f) => g a -> g b) -> [a] -> [b]
foo tr x = tr x
t = foo (fmap not) [True]
```
type-checks with 7.4.1 but not with 7.8.2. The latter reports the
error
```
Couldn't match type `b' with `Bool'
`b' is untouchable
inside the constraints (Functor f, g ~ f)
bound by a type expected by the context:
(Functor f, g ~ f) => g Bool -> g b
at /tmp/t.hs:12:5-25
`b' is a rigid type variable bound by
the inferred type of t :: [b] at /tmp/t.hs:12:1
Expected type: Bool -> b
Actual type: Bool -> Bool
Relevant bindings include t :: [b] (bound at /tmp/t.hs:12:1)
In the first argument of `fmap', namely `not'
In the first argument of `foo', namely `(fmap not)'
```
Giving `t` the type signature `[Bool]` fixes the problem. Alas, I come across the similar untouchable error in situations where giving the type signature is quite difficult (in local bindings, with quite large types).
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 7.8.2 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture | |
</details>
<!-- {"blocked_by":[],"summary":"Untouchable type variable (regression from 7.6)","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"7.8.2","keywords":[],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"Oleg says: what used to type check in GHC 7.4.1 (and I think\r\nin 7.6.2, although I no longer have access to that version) fails in\r\nGHC 7.8.2.\r\n\r\nThe following program type-checks with GHC 7.4.1 and GHC 7.8.2:\r\n{{{\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n\r\nmodule T where\r\n\r\nfoo :: (forall f g. (Functor f) => f a -> f b) -> [a] -> [b]\r\n-- foo :: (forall f g. (Functor f, g ~ f) => g a -> g b) -> [a] -> [b]\r\nfoo tr x = tr x\r\n\r\nt = foo (fmap not) [True]\r\n}}}\r\nThe following code (which differs only in the signature of foo)\r\n{{{\r\n{-# LANGUAGE RankNTypes #-}\r\n{-# LANGUAGE TypeFamilies #-}\r\n\r\nmodule T where\r\n\r\n-- foo :: (forall f g. (Functor f) => f a -> f b) -> [a] -> [b]\r\nfoo :: (forall f g. (Functor f, g ~ f) => g a -> g b) -> [a] -> [b]\r\nfoo tr x = tr x\r\n\r\nt = foo (fmap not) [True]\r\n}}}\r\n\r\ntype-checks with 7.4.1 but not with 7.8.2. The latter reports the\r\nerror\r\n{{{\r\n Couldn't match type `b' with `Bool'\r\n `b' is untouchable\r\n inside the constraints (Functor f, g ~ f)\r\n bound by a type expected by the context:\r\n (Functor f, g ~ f) => g Bool -> g b\r\n at /tmp/t.hs:12:5-25\r\n `b' is a rigid type variable bound by\r\n the inferred type of t :: [b] at /tmp/t.hs:12:1\r\n Expected type: Bool -> b\r\n Actual type: Bool -> Bool\r\n Relevant bindings include t :: [b] (bound at /tmp/t.hs:12:1)\r\n In the first argument of `fmap', namely `not'\r\n In the first argument of `foo', namely `(fmap not)'\r\n}}}\r\nGiving `t` the type signature `[Bool]` fixes the problem. Alas, I come across the similar untouchable error in situations where giving the type signature is quite difficult (in local bindings, with quite large types).\r\n","type_of_failure":"OtherFailure","blocking":[]} -->
issue