[Haskell-beginners] Difference between types and values
Ovidiu Deac
ovidiudeac at gmail.com
Tue Jun 16 08:55:13 UTC 2015
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 <bob at redivi.com> 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 <
> matt.williams45.mw at gmail.com> 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
>> Beginners at haskell.org
>> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>>
>>
>
> _______________________________________________
> Beginners mailing list
> Beginners at 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/20150616/a4195d9a/attachment.html>
More information about the Beginners
mailing list