Created
April 3, 2011 07:28
-
-
Save jspahrsummers/900266 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data List a = | |
Nil | | |
Cons a (List a) | |
listLength :: Num b => List a -> b | |
listLength Nil = 0 | |
listLength (Cons x xs) = 1 + listLength xs | |
listHead :: List a -> a | |
listHead (Cons x xs) = x | |
listTail :: List a -> List a | |
listTail (Cons x xs) = xs | |
listFoldl :: (a -> b -> a) -> a -> List b -> a | |
listFoldl f a Nil = a | |
-- my version | |
listFoldl f a (Cons x xs) = f (listFoldl f a xs) x | |
-- from the tutorial solution at http://en.wikibooks.org/wiki/Haskell/YAHT/Type_basics/Solutions#Recursive_Datatypes | |
--listFoldl f y (Cons x xs) = listFoldl f (f y x) xs | |
listFoldr :: (a -> b -> b) -> b -> List a -> b | |
listFoldr f a Nil = a | |
listFoldr f a (Cons x xs) = f x (listFoldr f a xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment