[Haskell-beginners] Type signatures returned with :t
Francesco Ariis
fa-ml at ariis.it
Sat Sep 18 22:41:58 UTC 2021
Il 18 settembre 2021 alle 17:30 Galaxy Being ha scritto:
> > :t Just True
> Just True :: Maybe Bool
> > :t Left True
> Left True :: Either Bool b
> > :t Right False
> Right False :: Either a Bool
>
> What am I being told here? It seems
> are both straightforward parameterized types, but Maybe doesn't give me a
> type parameter back, while Either does, and in different order, different
> names (a becomes b; b becomes a) depending on which variable I invoke. What
> deeper lore am I not seeing here?
When you ask the type of
λ> :t Just True
the interpreter *knows* that that `Maybe` is not just a `Maybe a` (so
type constructor and its type parameter) but the /concrete/ type `Maybe
Bool`. This would not be the case if we did
λ> :t Nothing
Nothing :: Maybe a
Same story with `Either`. Each of the two data constructors (`Left` and
`Right`) let the interpreter infer just *one* of the type parameters
(the `a` and `b` in `Either a b`).
Does this answer your question?
More information about the Beginners
mailing list