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.  Lambda calc version of Haskell lambda function
      (Lawrence Bottorff)
   2.  Type variables (Lawrence Bottorff)
   3. Re:  Type variables (Ut Primum)
   4. Re:  Lambda calc version of Haskell lambda function
      (Francesco Ariis)
   5. Re:  Type variables (Francesco Ariis)


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

Message: 1
Date: Thu, 31 Dec 2020 22:33:36 -0600
From: Lawrence Bottorff <borg...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Lambda calc version of Haskell lambda
        function
Message-ID:
        <CAFAhFSXSR3sTzM29brpK9OiZ_NCPaKPP8=oyqhc3gqh2lq+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Here is a function declaration

makeAddress :: Int -> String -> String -> (Int, String, String)
makeAddress number street town = (number,street,town)

and here is a lambda function version

makeAddressLambda =  (\number -> (\street -> (\town -> (number, street,
town))))

How would this lambda version look in lambda calculus? Like this?

\number.\street.\town.(number street town)

then

(\number.\street.\town.(number street town) (123 "Sunny St." "Fergus")
(\street.\town.(123 street town) ("Sunny St." "Fergus")
(\town.(123 "Sunny St.") ("Fergus")
(123 "Sunny St." "Fergus")

Not always sure.

LB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20201231/34ec6fe3/attachment-0001.html>

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

Message: 2
Date: Thu, 31 Dec 2020 23:04:19 -0600
From: Lawrence Bottorff <borg...@gmail.com>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Subject: [Haskell-beginners] Type variables
Message-ID:
        <CAFAhFSUHTEXQE_YweRBAx5=cbts6oxouyf4hww+streewea...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I put this into ghci

makeTriple :: a -> b -> c -> (a,b,c)
makeTriple x y z = (x,y,z)

then as expected

> :t makeTriple
: makeTriple :: a -> b -> c -> (a, b, c)

but then on a whim I try this

> :t (makeTriple 123 "Hi" 234.0)
 (makeTriple 123 "Hi" 234.0)
   :: (Fractional c, Num a) => (a, [Char], c)

I retry

> :t (123,"Hi",234.0)
(123,"Hi",234.0) :: (Fractional c, Num a) => (a, [Char], c)

What is this telling me? I'm not experienced enough to decode this.

LB
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20201231/e27bffc3/attachment-0001.html>

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

Message: 3
Date: Fri, 1 Jan 2021 10:25:03 +0100
From: Ut Primum <utpri...@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 variables
Message-ID:
        <canjdmk+xgajeuomqeooxdkgr-9qas-grvq_qkdhaqwxbxn9...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,

the first time you asked for the type of the function MakeTriple, which as
you expected takes 3 arguments of generic types a, b and c and returns
something of type (a,b,c).

The second time you asked for the type of MakeTriple applied to three
specific arguments. This time the result is no more the type of a function,
but is just the type of the result, which is exactly the same as the type of
(123,"Hi",234.0)

Maybe now your question is why that expression has the type you obtain.

First of all, what is at the left of the symbol
=>
are class constraints. This means that they tell you that now c is not "any
type" (as it was in the type of MakeTriple), but is "any type in the class
Fractional". So it could be for example of type Float or Double, which are
two different types but both in the class Fractional.
Similarly Num a means that a can be "any type in the class Num" (so it can
be Int, Integer, Float etc.).
The same class constraint you obtain if you ask for the type of 12.

Then at the right of the => symbol, you have the type of your expression,
where a and c are not completely generic types, because of the contraints
expressed before.

happy new year,
Ut


Il ven 1 gen 2021, 06:15 Lawrence Bottorff <borg...@gmail.com> ha scritto:

> I put this into ghci
>
> makeTriple :: a -> b -> c -> (a,b,c)
> makeTriple x y z = (x,y,z)
>
> then as expected
>
> > :t makeTriple
> : makeTriple :: a -> b -> c -> (a, b, c)
>
> but then on a whim I try this
>
> > :t (makeTriple 123 "Hi" 234.0)
>  (makeTriple 123 "Hi" 234.0)
>    :: (Fractional c, Num a) => (a, [Char], c)
>
> I retry
>
> > :t (123,"Hi",234.0)
> (123,"Hi",234.0) :: (Fractional c, Num a) => (a, [Char], c)
>
> What is this telling me? I'm not experienced enough to decode this.
>
> LB
> _______________________________________________
> 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/20210101/1f8d10c7/attachment-0001.html>

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

Message: 4
Date: Fri, 1 Jan 2021 10:58:16 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Lambda calc version of Haskell lambda
        function
Message-ID: <20210101095816.GA30146@extensa>
Content-Type: text/plain; charset=utf-8

Il 31 dicembre 2020 alle 22:33 Lawrence Bottorff ha scritto:
> Here is a function declaration
> 
> makeAddress :: Int -> String -> String -> (Int, String, String)
> makeAddress number street town = (number,street,town)
> 
> and here is a lambda function version
> 
> makeAddressLambda =  (\number -> (\street -> (\town -> (number, street,
> town))))

You can lose most of the parentheses:

    makeAddressLambda =  \number -> \street -> \town -> (number, street, town)

> How would this lambda version look in lambda calculus? Like this?
> 
> \number.\street.\town.(number street town)

Yes.

> then
> 
> (\number.\street.\town.(number street town) (123 "Sunny St." "Fergus")

Wait! You have lost a ‘)’ on the lambdas (remember λ goes as far right as
possible). Also

    (123, "Sunny St.", "Fergus")

makes it look like it is a single argument, which leads to a wrong result:

    (λnumber. λstreet. λtown. number street town) (123, "Sunny St.", "Fergus")
    λstreet. λtown. (123, "Sunny St.", "Fergus") street town
    -- woops!

Instead, keeping in mind Haskell follows a beta-nu-mu strategy, we have
a series of 3 βs:

    (λnumber. λstreet. λtown. (number, street, town)) 123 "Sunny St." "Fergus"
    (λstreet. λtown. (123, street, town) "Sunny St." "Fergus"
    (λtown. (123, "Sunny St.", town) "Fergus"
    (123, "Sunny St.", "Fergus")



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

Message: 5
Date: Fri, 1 Jan 2021 11:20:02 +0100
From: Francesco Ariis <fa...@ariis.it>
To: beginners@haskell.org
Subject: Re: [Haskell-beginners] Type variables
Message-ID: <20210101102002.GA20222@extensa>
Content-Type: text/plain; charset=utf-8

Il 31 dicembre 2020 alle 23:04 Lawrence Bottorff ha scritto:
> > :t (123,"Hi",234.0)
> (123,"Hi",234.0) :: (Fractional c, Num a) => (a, [Char], c)

When you do not write a signature yourself GHC/GHCi tries to infer it.
Alas — for certain types — GHC tries to default it

    -- prova.hs
    a = (123, "Hi", 234.0)
    λ> :load prova.hs
    [1 of 1] Compiling Main             ( prova.hs, interpreted )
    Ok, one module loaded.
    λ> :t a
    a :: (Integer, [Char], Double)

while GHCi goes for a more general type

    λ> b = (123, "Hi", 234.0)
    λ> :t b
    (123,"Hi",234.0) :: (Fractional c, Num a) => (a, [Char], c)

A couple of considerations:
- those are typeclasses — tl;dr they are interfaces providing a specific type
  of polymorphism. Ignore them for now if your text hasn’t explained them
  yet.
- When GHCi gives a type signature with typeclasses but you would rather see
  concrete types, use `+d`

    λ> :t +d b
    b :: (Integer, [Char], Double)



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

Subject: Digest Footer

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


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

End of Beginners Digest, Vol 150, Issue 1
*****************************************

Reply via email to