[Haskell-cafe] Producing MinimumValue

Hugh Perkins hughperkins at gmail.com
Thu Jul 19 14:03:51 EDT 2007

You can get the head and the tail by pattern matching.  Lets say you have a
function that takes a list:

myfunction list = -- do something here

go = myfuction [1,4,2,6]

... you can write the "list" bit of the function as (x:xs), where x is the
head, or first element, of the list, and xs is the tail, or the rest of the

myfunction (x:xs) = -- do something here

then you can call myfunction on xs, and compare that to x, to give the

This is recursive: the function calls itself over and over again, until at
some point it's going to execute "myfuction []" or "myfunction [6]", which
is easy to handle, for example by adding the definition:

myfunction [a] = -- the value of myfunction given a

Go here for a really great tutorial:


Recursive functions are in slides, number 6, but the tutorials are really
great: just start from 1 and work your way through.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070719/325b9a05/attachment.htm

More information about the Haskell-Cafe mailing list