Let's look at these functions' types for example:
:t traverse
traverse
:: (Applicative f, Traversable t) => (a -> f b) -> t a -> f (t b)
:t id
id :: a -> a
They have no concrete types, but have generic type parameters:
a
, f
, b
, t
(correct me if they called not generic type parameters please)
If I combine id
and traverse
together in this way,
:t traverse id [Just 1, Just 2, Nothing]
traverse id [Just 1, Just 2, Nothing] :: Num b => Maybe [b]
Haskell can now bind some concrete types for the type variables a
, f
, b
, t
.
t = []
a = Maybe bb
f = Maybe
b = Num bb => bb
Below I infer the types and mappings to parameters by hand, is there any way or tool in Haskell to do this automatically, so that it takes some composed parts (id
and traverse
) in an example, extracts their type signatures in general, and on output produces a mapping from generic type parameters names to concrete inferred types?
See also the first example here: https://wiki.haskell.org/Type_inference
for expression "map ord
" on how Haskell finds bindings of actual types to names.
So when we look at functions separately we only have names a
, f
, b
, t
. But then we combine the functions and provide some extra information like [Just 1, Just 2, Nothing]
, and the names a
, f
, b
, t
are mapped to concrete types.
I want to catch and show this mapping automatically.