update in-place
Ketil Malde
ketil@ii.uib.no
02 Oct 2001 17:19:27 +0200
"Cagdas Ozgenc" <co19@cornell.edu> writes:
> Could you help me on this notation?
Perhaps?
>> data Foo = Foo { a :: Int, b :: String }
This declares a Foo constructor with two named fields, and Int "a" and
a String "b". This is equivalent to declaring
data Foo = Foo Int String
but with a couple of extra features added, among others that
you automatically get defined functions "a" and "b" which take a Foo
object and return the values of the respective parts.
>> instance Show Foo where
>> show f = show (a f) ++ " " ++ show (b f)
...so the (a f) and (b f) parts are just extracting the relevant
information from the Foo.
If you know Lisp, it's fairly similar to defstruct.
-kzm
--
If I haven't seen further, it is by standing in the footprints of giants