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.  Difference between types and values (Matt Williams)
   2. Re:  Difference between types and values (Martin Vlk)
   3. Re:  Difference between types and values (Karl Voelker)
   4. Re:  Difference between types and values (Bob Ippolito)
   5. Re:  Difference between types and values (Ovidiu Deac)


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

Message: 1
Date: Tue, 16 Jun 2015 06:52:08 +0000
From: Matt Williams <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Difference between types and values
Message-ID:
        <caftvgqzuvve6k2-hjmxoak_xebbgn-ysyxfzfart7svo6_t...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Dear All,

I am sure this is a common mistake, and I am happy to be pointed elsewhere
for reading.

I have spent the last couple of days on the Haskell irc channel, which was
very helpful.

However, one of the points of discussion left me confused.

When we have a type, T, with constructors A and B

(e.g. data T = A x y z | B x y)

How do I understand the relationship between A, B and T? I had thought I
could use the sub-class relationship, but that doesn't seem to be true.

Any other pointers very welcome.

Matt
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150616/01182ec4/attachment-0001.html>

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

Message: 2
Date: Tue, 16 Jun 2015 07:26:16 +0000
From: Martin Vlk <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Difference between types and values
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252

One useful way to understand this is to note you will see T in type
annotations and A, B in your actual code.

I.e. T is a type constructor and A, B are data constructors.

M.

Matt Williams:
> Dear All,
> 
> I am sure this is a common mistake, and I am happy to be pointed elsewhere
> for reading.
> 
> I have spent the last couple of days on the Haskell irc channel, which was
> very helpful.
> 
> However, one of the points of discussion left me confused.
> 
> When we have a type, T, with constructors A and B
> 
> (e.g. data T = A x y z | B x y)
> 
> How do I understand the relationship between A, B and T? I had thought I
> could use the sub-class relationship, but that doesn't seem to be true.
> 
> Any other pointers very welcome.
> 
> Matt
> 
> 
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> 


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

Message: 3
Date: Tue, 16 Jun 2015 00:42:16 -0700
From: Karl Voelker <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Difference between types and values
Message-ID:
        <1434440536.2636752.296669137.3cfa9...@webmail.messagingengine.com>
Content-Type: text/plain; charset="us-ascii"

On Mon, Jun 15, 2015, at 11:52 PM, Matt Williams wrote:
> When we have a type, T, with constructors A and B


> (e.g. data T = A x y z | B x y)


> How do I understand the relationship between A, B and T? I had
> thought I could use the sub-class relationship, but that doesn't seem
> to be true.


You are correct that A and B are not types in Haskell.

The relationship is that there are two different ways to construct a
value of type T. Whenever a T is needed, you can use either A or B. That
means, on the other hand, that whenever a T is consumed, you have to
handle two cases: A and B.

These data types are called "algebraic data types," which might help you
find more to read about them. The wiki has a page:
https://wiki.haskell.org/Algebraic_data_type.

Lastly, as a bit of a digression, you could imagine an alternate
language in which A and B are subtypes of T, such that constructor A
returns a value of type A, and constructor B returns a value of type B.
I'm not an expert on the theory behind all of this, but I know that
doing type inference would be much harder in such a language.

-Karl
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150616/6bfd1e8d/attachment-0001.html>

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

Message: 4
Date: Tue, 16 Jun 2015 09:42:36 +0200
From: Bob Ippolito <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Difference between types and values
Message-ID:
        <CACwMPm_AvHy2gjo87AuC6Oq809omzg=qpwq5triirn56v_l...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

T is the type. A and B are the only constructors for values of that type. A
and B are not terms in the type language. T is not a term in the value
language.

It's simpler to consider a type without any fields in the constructor:

data Bool = True | False

True and False are values, Bool is the type. You can't use Bool as a
constructor, and you can't use True or False as a type.

When you add fields it can get a bit more confusing, because the fields of
a constructor are types, so it looks like "ValueConstructor1 FieldType1
FieldType2 | ValueConstructor2 FieldType3"

data PersonOrPlace = Person String | Place String

To make it more clear, here the types are annotated with <AngleBrackets>
and the constructors annotated with [SquareBrackets]:

data <PersonOrPlace> = [Person] <String> | [Place] <String>



On Tue, Jun 16, 2015 at 8:52 AM, Matt Williams <[email protected]
> wrote:

> Dear All,
>
> I am sure this is a common mistake, and I am happy to be pointed elsewhere
> for reading.
>
> I have spent the last couple of days on the Haskell irc channel, which was
> very helpful.
>
> However, one of the points of discussion left me confused.
>
> When we have a type, T, with constructors A and B
>
> (e.g. data T = A x y z | B x y)
>
> How do I understand the relationship between A, B and T? I had thought I
> could use the sub-class relationship, but that doesn't seem to be true.
>
> Any other pointers very welcome.
>
> Matt
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150616/0fbea222/attachment-0001.html>

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

Message: 5
Date: Tue, 16 Jun 2015 11:55:13 +0300
From: Ovidiu Deac <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Difference between types and values
Message-ID:
        <cakvse7s-1kr9vr-2iacaoezzqudeyt6ixyohrj2zmv0g+zu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

I want to add a little more thing that makes me understand this easier:

    data Bool = True | False

You can think if True not as a value but as a function from unit to Bool

That being said in Bob's example:

    data PersonOrPlace = Person String | Place String

...Person is a function from the type String to the type PersonOrPlace

As a conclusion: Haskell is, as they say, "a strong & static typed purely
functional language", everything is either a type or a function. If it's
not a type then it must be a function. You can say that even 0 is a
function from unit to Int so it works quite nice.


On Tue, Jun 16, 2015 at 10:42 AM, Bob Ippolito <[email protected]> wrote:

> T is the type. A and B are the only constructors for values of that type.
> A and B are not terms in the type language. T is not a term in the value
> language.
>
> It's simpler to consider a type without any fields in the constructor:
>
> data Bool = True | False
>
> True and False are values, Bool is the type. You can't use Bool as a
> constructor, and you can't use True or False as a type.
>
> When you add fields it can get a bit more confusing, because the fields of
> a constructor are types, so it looks like "ValueConstructor1 FieldType1
> FieldType2 | ValueConstructor2 FieldType3"
>
> data PersonOrPlace = Person String | Place String
>
> To make it more clear, here the types are annotated with <AngleBrackets>
> and the constructors annotated with [SquareBrackets]:
>
> data <PersonOrPlace> = [Person] <String> | [Place] <String>
>
>
>
> On Tue, Jun 16, 2015 at 8:52 AM, Matt Williams <
> [email protected]> wrote:
>
>> Dear All,
>>
>> I am sure this is a common mistake, and I am happy to be pointed
>> elsewhere for reading.
>>
>> I have spent the last couple of days on the Haskell irc channel, which
>> was very helpful.
>>
>> However, one of the points of discussion left me confused.
>>
>> When we have a type, T, with constructors A and B
>>
>> (e.g. data T = A x y z | B x y)
>>
>> How do I understand the relationship between A, B and T? I had thought I
>> could use the sub-class relationship, but that doesn't seem to be true.
>>
>> Any other pointers very welcome.
>>
>> Matt
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150616/a4195d9a/attachment-0001.html>

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

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


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

End of Beginners Digest, Vol 84, Issue 25
*****************************************

Reply via email to