Closed wiwa closed 8 years ago
This is a limitation in GHC as far as I know. It tries to only apply type synonyms in places where they are actually relevant which is going to not give what you want sometimes. Imagine if you imported a type synonym type Foo = String
from some module. Would you want GHC to rewrite every occurrence of String
with Foo
? And what if some other package/module you're also importing defines type Bar = String
, which one would it use?
Interesting, that makes sense. What are these places in which it would apply type synonyms?
I think it would be anything that doesn't try to unify Foo
with anything else and ends up having to look inside the synonym, some examples:
> type Foo = String
> let strfoo :: String -> Foo; strfoo = id
These just unify Foo ~ a
so GHC can keep the type synonym intact:
> :t strfoo ""
strfoo "" :: Foo
> :t id $ strfoo ""
id $ strfoo "" :: Foo
> :t repeat $ strfoo ""
repeat $ strfoo "" :: [Foo]
> :t (:[]) $ strfoo ""
(:[]) $ strfoo "" :: [Foo]
> :t repeat $ strfoo ""
repeat $ strfoo "" :: [Foo]
whereas these have to unify Foo ~ [a]
so it can't:
> :t (++) "" $ strfoo ""
(++) "" $ strfoo "" :: [Char]
> :t cycle $ strfoo ""
cycle $ strfoo "" :: [Char]
Closing, as this is out of scope for this package.
Given:
I would except a function with type-inferred signature
[Int]
to have a signature ofManyInt
if I use "Insert Type" from the right-click menu. However, it continues to use[Int]
.