New to Haskell

Hal Daume t-hald@microsoft.com
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.

HTH
 - Hal

 --
 Hal Daume III                                   | hdaume@isi.edu
 "Arrest this man, he talks in maths."           | www.isi.edu/~hdaume


> -----Original Message-----
> From: haskell-cafe-admin@haskell.org=20
> [mailto:haskell-cafe-admin@haskell.org] On Behalf Of Matthew Morvant
> Sent: Thursday, August 28, 2003 8:44 AM
> To: 'Haskell (haskell-cafe@haskell.org)'
> Subject: New to Haskell
>=20
>=20
> Hello,
>     I am very new to haskell.  I was hoping someone could=20
> explain something
> to me
>=20
> 	fname          :: [([Char],a)] -> String
> 	fname []          =3D "Result_Blank"
> 	fname ((x,xs):ys) =3D x
>=20
> What exactly [use little words :-)] does this do?
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>=20