TypeApplications and DefaultSignatures - problems deducing type variables.
The following example code throws an error.
The example code:
```hs
{-#LANGUAGE TypeApplications#-}
{-#LANGUAGE MultiParamTypeClasses #-}
{-#LANGUAGE AllowAmbiguousTypes #-}
{-#LANGUAGE FlexibleInstances #-}
{-#LANGUAGE ScopedTypeVariables #-}
{-#LANGUAGE DefaultSignatures #-}
module Test1 where
-- | Type a is only used for
-- type application.
class ToUse a where
toUse :: Int -> Int
-- | The type used for
-- type application
data Default
-- | The instance using Default as type application.
-- To call use:
-- > toUse @Default
instance ToUse Default where
toUse a = 3*a
-- | Typeclass whose methods work
-- only with type application.
class (ToUse a) => Uses a b where
uses :: b -> [b]
-- | Default Signature, which generates the problem.
-- It is the same as the normal one
-- Comment it to 'fix' the bug.
default uses :: b -> [b]
uses v = [v]
-- | Normal instances, nothing special
instance Uses Default Int where
uses v = take (toUse @Default 3) $ repeat v
-- | Another normal one
instance Uses Default String where
uses v = take (toUse @Default 2) $ repeat v
-- | This one works nicely
instance (ToUse t, Uses t a, Uses t b) => Uses t (a,b) where
uses (vl,vr) = zip ls rs
where ls = uses @t vl
rs = uses @t vr
-- | But this one doesn't.
-- Unless you comment the default signature.
instance (ToUse t, Uses t a, Uses t b, Uses t c) => Uses t (a,b,c)
```
The error:
```
• Could not deduce (Uses a0 a)
arising from a use of ‘Test1.$dmuses’
from the context: (ToUse t, Uses t a, Uses t b, Uses t c)
bound by the instance declaration at Test1.hs:47:10-66
The type variable ‘a0’ is ambiguous
Relevant bindings include
uses :: (a, b, c) -> [(a, b, c)] (bound at Test1.hs:47:10)
• In the expression: Test1.$dmuses
In an equation for ‘uses’: uses = Test1.$dmuses
In the instance declaration for ‘Uses t (a, b, c)’
```
Commenting out the default signature fixes the problem.
<details><summary>Trac metadata</summary>
| Trac field | Value |
| ---------------------- | ------------ |
| Version | 8.0.1 |
| 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":"TypeApplications and DefaultSignatures - problems deducing type variables.","status":"New","operating_system":"","component":"Compiler","related":[],"milestone":"","resolution":"Unresolved","owner":{"tag":"Unowned"},"version":"8.0.1","keywords":["DefaultSignatures,","TypeApplications"],"differentials":[],"test_case":"","architecture":"","cc":[""],"type":"Bug","description":"The following example code throws an error.\r\n\r\nThe example code:\r\n{{{#!hs\r\n{-#LANGUAGE TypeApplications#-}\r\n{-#LANGUAGE MultiParamTypeClasses #-}\r\n{-#LANGUAGE AllowAmbiguousTypes #-}\r\n{-#LANGUAGE FlexibleInstances #-}\r\n{-#LANGUAGE ScopedTypeVariables #-}\r\n{-#LANGUAGE DefaultSignatures #-}\r\nmodule Test1 where\r\n\r\n-- | Type a is only used for\r\n-- type application.\r\nclass ToUse a where\r\n toUse :: Int -> Int\r\n\r\n-- | The type used for\r\n-- type application\r\ndata Default\r\n\r\n\r\n-- | The instance using Default as type application.\r\n-- To call use:\r\n-- > toUse @Default \r\ninstance ToUse Default where\r\n toUse a = 3*a\r\n\r\n-- | Typeclass whose methods work\r\n-- only with type application.\r\nclass (ToUse a) => Uses a b where\r\n uses :: b -> [b]\r\n -- | Default Signature, which generates the problem.\r\n -- It is the same as the normal one\r\n -- Comment it to 'fix' the bug.\r\n default uses :: b -> [b] \r\n uses v = [v] \r\n\r\n-- | Normal instances, nothing special\r\ninstance Uses Default Int where\r\n uses v = take (toUse @Default 3) $ repeat v\r\n-- | Another normal one\r\ninstance Uses Default String where\r\n uses v = take (toUse @Default 2) $ repeat v\r\n\r\n-- | This one works nicely\r\ninstance (ToUse t, Uses t a, Uses t b) => Uses t (a,b) where\r\n uses (vl,vr) = zip ls rs\r\n where ls = uses @t vl\r\n rs = uses @t vr\r\n\r\n-- | But this one doesn't.\r\n-- Unless you comment the default signature.\r\ninstance (ToUse t, Uses t a, Uses t b, Uses t c) => Uses t (a,b,c)\r\n}}}\r\n\r\n\r\nThe error:\r\n{{{\r\n • Could not deduce (Uses a0 a)\r\n arising from a use of ‘Test1.$dmuses’\r\n from the context: (ToUse t, Uses t a, Uses t b, Uses t c)\r\n bound by the instance declaration at Test1.hs:47:10-66\r\n The type variable ‘a0’ is ambiguous\r\n Relevant bindings include\r\n uses :: (a, b, c) -> [(a, b, c)] (bound at Test1.hs:47:10)\r\n • In the expression: Test1.$dmuses\r\n In an equation for ‘uses’: uses = Test1.$dmuses\r\n In the instance declaration for ‘Uses t (a, b, c)’\r\n}}}\r\n\r\nCommenting out the default signature fixes the problem. ","type_of_failure":"OtherFailure","blocking":[]} -->
issue