
So in the wiki on AbstractDataType ( http://haskell.org/hawiki/AbstractDataType ) it gives the following example: data Tree a = Nil | Node { left :: Tree a, value :: a, right :: Tree a } The part where I am confused is with the use of '{' and '}' my reference book is apparently out of date as it states that Haskell doesn't even use those characters :) Could someone point me to some documentation on whats being created here and how its used? thank you Jason

On Sun, 12 Dec 2004 13:08:30 -0500, Jason Bailey
So in the wiki on AbstractDataType ( http://haskell.org/hawiki/AbstractDataType )
it gives the following example:
data Tree a = Nil | Node { left :: Tree a, value :: a, right :: Tree a }
The part where I am confused is with the use of '{' and '}' my reference book is apparently out of date as it states that Haskell doesn't even use those characters :)
Could someone point me to some documentation on whats being created here and how its used?
It's basically a shorthand for writing accessor functions. You could do something like: data Tree a = Nil | Node (Tree a) a (Tree a) left (Node l _ _) = l value (Node _ v _) = v right (Node _ _ r) = r /S -- Sebastian Sylvan +46(0)736-818655 UIN: 44640862

On Sun, Dec 12, 2004 at 07:46:42PM +0100, Sebastian Sylvan wrote:
Could someone point me to some documentation on whats being created here and how its used?
It's basically a shorthand for writing accessor functions.
You could do something like: data Tree a = Nil | Node (Tree a) a (Tree a) left (Node l _ _) = l value (Node _ v _) = v right (Node _ _ r) = r
Record field labels can be also used in pattern matching and in record update. Especially the latter is very useful. For more information, see The Haskell 98 Report. Best regards, Tomasz

Tomasz Zielonka
Record field labels can be also used in pattern matching and in record update. Especially the latter is very useful.
But not quite as elegant -- while record query lets you modify the underlying structure and replace the old record queries with functions, I don't think there's a way to do this for record updates (or am I wrong?) -kzm -- If I haven't seen further, it is by standing in the footprints of giants

On Mon, Dec 13, 2004 at 11:29:56AM +0100, Ketil Malde wrote:
Tomasz Zielonka
writes: Record field labels can be also used in pattern matching and in record update. Especially the latter is very useful.
But not quite as elegant -- while record query lets you modify the underlying structure and replace the old record queries with functions, I don't think there's a way to do this for record updates (or am I wrong?)
No, I think you are right. Best regards, Tomasz
participants (4)
-
Jason Bailey
-
Ketil Malde
-
Sebastian Sylvan
-
Tomasz Zielonka