New to Haskell
Thu, 28 Aug 2003 08:50:40 -0700
the first line says that 'fname' is a function which takes a list and
returns a string. the list is of type '[([Char],a)]'. this means that
it's a list of ([Char],a)s. these are pairs of [Char]s and as. a
[Char] is a string (a string is a list of characters) and an a is a
something -- anything you want.
the second line tells you the value of fname when its argument list is
empty (). the result in this case is the string "Result_Blank".
the third line tells you what to do when the input is not empty. when
you have a non-empty list, it's composed of a head and a tail, written
(head:tail). since our list is of pairs, the head has the form (a,b).
putting this together, we have that the list is of the form ((x,xs):ys).
here, x is our a, xs is our b and ys is the tail. (x,xs) is our head.
it then says that the result of this is just the value 'x'. this is
simply the [Char] part (the first half) of the first pair in the list.
Hal Daume III | firstname.lastname@example.org
"Arrest this man, he talks in maths." | www.isi.edu/~hdaume
> -----Original Message-----
> From: email@example.com=20
> [mailto:firstname.lastname@example.org] On Behalf Of Matthew Morvant
> Sent: Thursday, August 28, 2003 8:44 AM
> To: 'Haskell (email@example.com)'
> Subject: New to Haskell
> I am very new to haskell. I was hoping someone could=20
> explain something
> to me
> fname :: [([Char],a)] -> String
> fname  =3D "Result_Blank"
> fname ((x,xs):ys) =3D x
> What exactly [use little words :-)] does this do?
> Haskell-Cafe mailing list