View Full Version : my first function in Haskell
inkedmn
12-09-2002, 10:50 PM
yes, it's just a factorial, but it's quite a long time in the making (just ask Strike :))
factorial :: Integer -> Integer
factorial 0 = 1
factorial x = x * factorial (x-1)
:)
inkedmn
12-09-2002, 11:45 PM
and my second :)
mymap x [] = []
mymap x (y:ys) = [x y] ++ mymap x ys
thanks to Strike and Vince all the assistance :)
GnuVince
12-09-2002, 11:56 PM
Third one's coming as we speak ladies and gentlemen!
Strike
12-10-2002, 12:41 AM
a note: we fixed the mymap function:
mymap func [] = []
mymap func (x:xs) = func x : mymap func xs
inkedmn
12-10-2002, 12:53 AM
as promised by vince:
mult [a] = a
mult (x:xs) = x * mult xs
this takes a list and multiplies each element by the next, starting at the front of the list and returns the total
(the other one is an implementation of map)
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.