Send Beginners mailing list submissions to
[email protected]
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
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Type signatures returned with :t (Galaxy Being)
2. Re: Type signatures returned with :t (Francesco Ariis)
3. Re: Type signatures returned with :t (Galaxy Being)
4. Re: Type signatures returned with :t (Erik Dominikus)
5. Re: Type signatures returned with :t (Andreas Perstinger)
----------------------------------------------------------------------
Message: 1
Date: Sat, 18 Sep 2021 17:30:17 -0500
From: Galaxy Being <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Type signatures returned with :t
Message-ID:
<CAFAhFSVtSj_D2y4OkYFz1dAbTxFD4oD8WaE3JCaHEv-e=-p...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
> :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
data Maybe a = Just a
| Nothing
data Either a b = Left a
| Right b
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?
--
⨽
Lawrence Bottorff
Grand Marais, MN, USA
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20210918/fe39d083/attachment-0001.html>
------------------------------
Message: 2
Date: Sun, 19 Sep 2021 00:41:58 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Type signatures returned with :t
Message-ID: <YUZrNkrUh23OsYse@extensa>
Content-Type: text/plain; charset=utf-8
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?
------------------------------
Message: 3
Date: Sat, 18 Sep 2021 21:19:09 -0500
From: Galaxy Being <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Type signatures returned with :t
Message-ID:
<cafahfsxht6p+rmyjttpmv92csdj8uctm5mxjxewtsgcftyq...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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 <[email protected]> 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
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
⨽
Lawrence Bottorff
Grand Marais, MN, USA
[email protected]
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20210918/73fa3562/attachment-0001.html>
------------------------------
Message: 4
Date: Sun, 19 Sep 2021 11:09:37 +0700
From: Erik Dominikus <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Type signatures returned with :t
Message-ID:
<CAOopUj=5_bJ3dPrL2U9bpR3kq9=r24hz7v916k55savdv89...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
> What deeper lore am I not seeing here?
The "deeper lore" you are looking for is:
- Type variables that look unbound are actually implicitly bound with a
universal quantifier:
- "Maybe a" is actually "forall a. Maybe a";
- "Either a b" is actually "forall a. forall b. Either a b", that is,
"forall a. (forall b. Either a b)";
- "Either a (Either b c)" is actually "forall a. forall b. forall c.
Either a (Either b c)";
- "a" is actually "forall a. a";
- "f a" is actually "forall f. forall a. f a".
- alpha-equivalence: You can rename the bound variables of an expression
without changing its meaning, as long as you don't change the bindings.
- Example of changing the bindings: "forall x. forall y. x" (x is
bound by the first/outer quantifier) is not alpha-equivalent to
"forall y.
forall x. x" (x is bound by the second/inner quantifier).
Examples of alpha-equivalence (here "≡" reads "is alpha-equivalent to"):
forall a. forall b. Either a b
≡ forall x. forall y. Either x y
≡ forall b. forall a. Either b a
forall a. Either Bool a
≡ forall b. Either Bool b
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20210919/446aac35/attachment-0001.html>
------------------------------
Message: 5
Date: Sun, 19 Sep 2021 06:46:35 +0200
From: Andreas Perstinger <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Type signatures returned with :t
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8; format=flowed
On 19.09.21 00:30, Galaxy Being wrote:
>> :t Just True
> Just True :: Maybe Bool
What's the type of `Just`?
> :t Just
Just :: a -> Maybe a
So `Just` is a constructor function that takes a value of type `a` and
gives you back a value of type `Maybe a`.
In your example you provide a concrete type for `a` (`True :: Bool`) so
the type of the result is `Maybe Bool`.
>> :t Left True
> Left True :: Either Bool b
As above what's the type of `Left`?
> :t Left
Left :: a -> Either a b
Again, `Left` is a constructor function that takes a single value of type
`a` but now returns a value of type `Either a b`, i.e. it has two type
variables.
If you specify the type of `a` (again `Bool` in your example), `b` is
still unspecified/polymorphic and that's why the resulting type is `Either
Bool b`.
Bye, Andreas
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 158, Issue 4
*****************************************