Skip to content

Instantly share code, notes, and snippets.

@vijaykiran
Created October 22, 2013 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vijaykiran/7097094 to your computer and use it in GitHub Desktop.
Save vijaykiran/7097094 to your computer and use it in GitHub Desktop.
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
Copy link

ghost commented Oct 22, 2013

myLength :: Num a => [t] -> a
myLength [] = 0
myLength (x:xs) = myLength xs + 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment