[Haskell-cafe] when does ghc(i) expand type synonyms?

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Wed Oct 25 16:37:18 UTC 2023

Dear cafe,

my students were asking:
why are types printed differently here?

ghci> :set +t

ghci> "foo"
it :: String

ghci> reverse "foo"
it :: [Char]

... and I add

ghci> fst ("foo", 42)
it :: String

compiler docs do not really explain the difference
(it says "display the type of .." while technically it is
"display some representation of the type of ..."?)

I found this explanation of a somewhat related issue

While playing around with this, I noticed:

ghci> let x = "foo" in (x <> reverse x)
it :: String

ghci> let x = "foo" in (x ++ reverse x)
it :: [Char]

Well, it's just optics: when I extract the type programmatically,
the synonym necessarily does get expanded

ghci> import Data.Data
ghci> typeOf (let x = "foo" in (x <> reverse x))
it :: TypeRep

- Johannes

More information about the Haskell-Cafe mailing list