[Haskell-cafe] ghci's choice of names for type variables

Johannes Waldmann johannes.waldmann at htwk-leipzig.de
Sat Oct 30 13:47:11 UTC 2021


Just from observing the behaviour (not the source) -
it seems that ghci tries to use the variables from the declaration
of the/a function, type, or class that is being used.


Prelude> data T c = T c
Prelude> h x y = (T x, T y)
Prelude> :t h
h :: c1 -> c2 -> (T c1, T c2)

Prelude> f :: foo -> foo ; f x = x
Prelude> g = f
Prelude> :t g
g :: foo -> foo

In the Haskell Standard, type variables are a, b, ... mostly (always?),
hence you get `a` for anything with lists and Num.


If there's no type to refer to, then your examples show
that it's using  t  or  p, but I don't know how.

Prelude> i x = x
Prelude> :t i
i :: p -> p

Prelude> k x y = x
Prelude> :t k
k :: p1 -> p2 -> p1

Prelude> s x y z = x z (y z)
Prelude> :t s
s :: (t1 -> t2 -> t3) -> (t1 -> t2) -> t1 -> t3

interesting!

- J.W.



More information about the Haskell-Cafe mailing list