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.
f :: forall x1…xn. twith type variablesx1…xnand typet, and an expression containingf, this would print all the values (of kindType) chosen forx1…xn. You may find the information you want in the output of the GHC flags-ddump-tc,-ddump-tc-ast, or-ddump-tc-trace.f↦Maybe,t↦[],a↦Maybe b0,b↦b0}. That works fine for functions, although not so much for more complex subterms. It is certainly a way to get there, just not exactly what I think was asked for—namely, the substitution.