[Haskell-beginners] Type signatures returned with :t

Joel Neely joel.neely at gmail.com
Sun Sep 19 17:13:59 UTC 2021


I hope the wizards will forgive a down-to-earth analogy.

Either a b is a knapsack with two pockets, the one on the Left (which must
hold an "a") and the one on the Right (which must hold a "b"). But you can
only use one pocket at a time.

So when there's a specific case of Either a b such as Left True, all that
can be concluded is that this is a case of an Either whose left pocket must
be able to handle a Bool; there's not enough information to know what could
have been put in the Right pocket. So only the left-pocket type ("a") can
be replaced with something specific.

Similarly, for a specific case of Right False, it's clear that the right
pocket holds a value of type Bool (replacing the general "b"), but there's
no information to identify what type might be in the left pocket. So it
remains unspecified.

I hope that helps.
-jn-

On Sat, Sep 18, 2021 at 9:21 PM Galaxy Being <borgauf at gmail.com> wrote:

> Either returns with its parameters, reversed, but Maybe did not. That's my
> main question.
>
> On Sat, Sep 18, 2021 at 5:43 PM Francesco Ariis <fa-ml at ariis.it> wrote:
>
>> 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?
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
> --
>> Lawrence Bottorff
> Grand Marais, MN, USA
> borgauf at gmail.com
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20210919/66ff678b/attachment.html>


More information about the Beginners mailing list