Send Beginners mailing list submissions to
        beginners@haskell.org

To subscribe or unsubscribe via the World Wide Web, visit
        http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Type signatures returned with :t (Erik Dominikus)
   2. Re:  Type signatures returned with :t (Joel Neely)


----------------------------------------------------------------------

Message: 1
Date: Sun, 19 Sep 2021 19:54:30 +0700
From: Erik Dominikus <erik.dominiku...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Type signatures returned with :t
Message-ID:
        <CAOopUjm+y=0cCy3o1Fwt7xyRzazSkPwMzn=zNnDTK=0gnu+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

> 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.

Try these diagnostics:

--- Diagnostic 1

Given that the type of "const" is "a -> b -> a" and the type of "True" is
"Bool":

:t const
const :: a -> b -> a

:t True
True :: Bool

What do you expect the type of "const True" to be?

:t const True
const True :: <what do you think goes here?>

   - If you answer "b -> Bool", you are correct, so you may be confused by
   the data type definition syntax (see below).
   - If you answer something else, you may be missing some basic
   understanding of the type system.


--- Diagnostic 2

Consider this case:

:t id
id :: a -> a

:t (id, id)
(id, id) :: (a1 -> a1, a2 -> a2)

   - If you think that the type of "(id, id)" should be "(a -> a, a -> a)",
   you may be unaware of the implicit universal quantifiers.


--- If you are confused by the data type definition syntax:

data Either a b
  = Left a
  | Right b

then, consider the GADT (generalized algebraic data type) definition syntax
for saying the same thing:

data Either a b where
  Left  :: a -> Either a b
  Right :: b -> Either a b

The problem becomes less confusing: The GADT definition syntax is screaming
that "Left" is a function like "id", "const", etc.

---

If you're still unsure, try thinking aloud here: Write your expectations
and why you think so (your thought process, what steps you took to arrive
at your expectations).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20210919/30018e68/attachment-0001.html>

------------------------------

Message: 2
Date: Sun, 19 Sep 2021 12:13:59 -0500
From: Joel Neely <joel.ne...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: Re: [Haskell-beginners] Type signatures returned with :t
Message-ID:
        <CAEEzXAhsD=Eb=90g85zeuncqvpgvotwwp0uiqcyjkcrq9tr...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

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 <borg...@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...@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@haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>
>
> --
> ⨽
> Lawrence Bottorff
> Grand Marais, MN, USA
> borg...@gmail.com
> _______________________________________________
> Beginners mailing list
> Beginners@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-0001.html>

------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 158, Issue 5
*****************************************

Reply via email to