Created
October 22, 2013 08:29
-
-
Save vijaykiran/7097094 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
myLength1 :: [a] -> Int | |
myLength1 [] = 0 | |
myLength1 (x:[]) = 1 | |
myLength1 (x:xs) = myLength1 xs + 1 | |
-- why ? | |
myLength2 :: (Eq t, Num a) => [t] -> a | |
myLength2 (x:xs) | xs == [] = 1 | |
| otherwise = myLength2 xs + 1 | |
myLength2 [] = 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
myLength :: Num a => [t] -> a
myLength [] = 0
myLength (x:xs) = myLength xs + 1