Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/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. data, records and functions (Emanuel Koczwara)
2. Re: data, records and functions (Darren Grant)
3. Re: data, records and functions (Peter Hall)
----------------------------------------------------------------------
Message: 1
Date: Wed, 20 Feb 2013 22:18:28 +0100
From: Emanuel Koczwara <[email protected]>
Subject: [Haskell-beginners] data, records and functions
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID: <1361395108.20925.4.camel@emanuel-Dell-System-Vostro-3750>
Content-Type: text/plain; charset="UTF-8"
Hi,
I'm watching Philip Wadler "Faith, Evolution, and Programming
Languages" (very cool by the way):
http://www.youtube.com/watch?v=8frGknO8rIg
At 00:24:14 there is strange thing on the slide:
data Ord a = { less :: a -> a -> Bool }
It's first time I see function type (and where is definition?) in record
syntax. Can somebody explain this?
Emanuel
------------------------------
Message: 2
Date: Wed, 20 Feb 2013 14:00:03 -0800
From: Darren Grant <[email protected]>
Subject: Re: [Haskell-beginners] data, records and functions
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<ca+jd6sihqhqkj+b8kmv-lflif+rfntjy+ror0t6othv21w4...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
This is just saying that the type of less is any function that takes two
a's as parameters and returns a Bool result. This appears to be a
formalization of the Ord (ordered) data type, where less would be used to
compare two ordered values and return a Bool result, either True or False.
Just a note that the data declaration above is missing a constructor name.
It should probably be something like:
data Ord a = *Ord* { less :: a -> a -> Bool }
Cheers,
Darren
On Wed, Feb 20, 2013 at 1:18 PM, Emanuel Koczwara <[email protected]
> wrote:
> Hi,
>
> I'm watching Philip Wadler "Faith, Evolution, and Programming
> Languages" (very cool by the way):
> http://www.youtube.com/watch?v=8frGknO8rIg
>
> At 00:24:14 there is strange thing on the slide:
>
> data Ord a = { less :: a -> a -> Bool }
>
> It's first time I see function type (and where is definition?) in record
> syntax. Can somebody explain this?
>
> Emanuel
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130220/4824f6ed/attachment-0001.htm>
------------------------------
Message: 3
Date: Thu, 21 Feb 2013 02:48:17 +0000
From: Peter Hall <[email protected]>
Subject: Re: [Haskell-beginners] data, records and functions
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Message-ID:
<CAA6hAk56uSOEgkvCFn5f=uhc1yrqk_tawhax2xyqo7up1_d...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
> It's first time I see function type (and where is definition?) in record
> syntax. Can somebody explain this?
There's no definition, it's a parameter to the constructor, so the function
can be anything. Taking a much simpler example, you'll be familiar with, if
you do:
data Foo a = Foo a
then the first argument to the Foo constructor also doesn't have a
definition. But when you use it to construct a value, then you provide one:
myFoo = Foo 3
Likewise, when you construct an Ord value, you supply a function as the
value for the 'less' parameter:
numOrd = Ord { less = (<) }
or you could use a different function for a different purpose:
listLengthOrd = Ord { less = \ a b => length a < length b }
Hope that helps,
Peter
On 20 February 2013 21:18, Emanuel Koczwara <[email protected]>wrote:
> Hi,
>
> I'm watching Philip Wadler "Faith, Evolution, and Programming
> Languages" (very cool by the way):
> http://www.youtube.com/watch?v=8frGknO8rIg
>
> At 00:24:14 there is strange thing on the slide:
>
> data Ord a = { less :: a -> a -> Bool }
>
> It's first time I see function type (and where is definition?) in record
> syntax. Can somebody explain this?
>
> Emanuel
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20130221/ea512314/attachment-0001.htm>
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 56, Issue 33
*****************************************