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. Re:  Difference between types and values
      (Sumit Sahrawat, Maths & Computing, IIT (BHU))
   2. Re:  Difference between types and values
      (Sumit Sahrawat, Maths & Computing, IIT (BHU))


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

Message: 1
Date: Tue, 16 Jun 2015 17:35:51 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
        <[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:
        <CAJbEW8N0z_mN0y5+CC4y3JZTKY=yx2pogwvwjz6fjncfxly...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

A short example:

    data T = Tag1 Type1 Type2
           | Tag2 Type3

    -- A type T can contain elements of two different types, which can be
differentiated in a program by their 'Tag'

    -- 'Tag1 Type1 Type2' is a product type, just like a cartesian product
of sets. It has elements
    -- of the form (Type1, Type2) but written as 'Tag1 Type1 Type2' for
programming convenience.

    -- Tag2 Type3 is just Type3, with additional syntax to differentiate it
from Type3.

    -- The pipe '|' creates a sum type, just like the union of sets.

    -- Overall, you have a type which has elements of the form (Type1,
Type2) or Type3. Written differently so that
    -- they can be distinguished from (Type1, Type2) and Type3 elements.

    -- (x :: Type1, y :: Type2) is not equal to 'Tag1 x y'.
    -- The first has the type (Type1, Type2) and the second has the type T.
    -- Thus, Tag1 takes a Type1 and a Type2 and converts them to a T.

    -- Tag1 :: Type1 -> Type2 -> T
    -- A data constructor, constructs element of type T using elements of
type Type1 and Type2

Read the two pages below, to get more intuition. Will be more helpful if
you come from C and know about unions in that language.

https://en.wikipedia.org/wiki/Algebraic_data_type
https://en.wikipedia.org/wiki/Tagged_union

Hope this helps.

On 16 June 2015 at 14:25, Ovidiu Deac <[email protected]> wrote:

> 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
>>
>>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>


-- 
Regards

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

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

Message: 2
Date: Tue, 16 Jun 2015 17:37:12 +0530
From: "Sumit Sahrawat, Maths & Computing, IIT (BHU)"
        <[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:
        <CAJbEW8PGsr7i6F=u08n3fybytlgylqz_rfpjwazmhb44u9g...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Ovidiu, take a look at this eye opener:
http://conal.net/blog/posts/everything-is-a-function-in-haskell

On 16 June 2015 at 17:35, Sumit Sahrawat, Maths & Computing, IIT (BHU) <
[email protected]> wrote:

> A short example:
>
>     data T = Tag1 Type1 Type2
>            | Tag2 Type3
>
>     -- A type T can contain elements of two different types, which can be
> differentiated in a program by their 'Tag'
>
>     -- 'Tag1 Type1 Type2' is a product type, just like a cartesian product
> of sets. It has elements
>     -- of the form (Type1, Type2) but written as 'Tag1 Type1 Type2' for
> programming convenience.
>
>     -- Tag2 Type3 is just Type3, with additional syntax to differentiate
> it from Type3.
>
>     -- The pipe '|' creates a sum type, just like the union of sets.
>
>     -- Overall, you have a type which has elements of the form (Type1,
> Type2) or Type3. Written differently so that
>     -- they can be distinguished from (Type1, Type2) and Type3 elements.
>
>     -- (x :: Type1, y :: Type2) is not equal to 'Tag1 x y'.
>     -- The first has the type (Type1, Type2) and the second has the type T.
>     -- Thus, Tag1 takes a Type1 and a Type2 and converts them to a T.
>
>     -- Tag1 :: Type1 -> Type2 -> T
>     -- A data constructor, constructs element of type T using elements of
> type Type1 and Type2
>
> Read the two pages below, to get more intuition. Will be more helpful if
> you come from C and know about unions in that language.
>
> https://en.wikipedia.org/wiki/Algebraic_data_type
> https://en.wikipedia.org/wiki/Tagged_union
>
> Hope this helps.
>
> On 16 June 2015 at 14:25, Ovidiu Deac <[email protected]> wrote:
>
>> 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
>>>
>>>
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
>
> --
> Regards
>
> Sumit Sahrawat
>



-- 
Regards

Sumit Sahrawat
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://mail.haskell.org/pipermail/beginners/attachments/20150616/a7936cfd/attachment.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 26
*****************************************

Reply via email to