[Haskell-beginners] data, records and functions
Peter Hall
peter.hall at memorphic.com
Thu Feb 21 03:48:17 CET 2013
> 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 <poczta at emanuelkoczwara.pl>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
> Beginners at haskell.org
> 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.htm>
More information about the Beginners
mailing list