Skip to content

Instantly share code, notes, and snippets.

@ToJans
Last active December 31, 2015 20:19
Show Gist options
  • Save ToJans/8039611 to your computer and use it in GitHub Desktop.
Save ToJans/8039611 to your computer and use it in GitHub Desktop.
You don't want to know how long the `mean`function took, just because I added the spec `myLength :: [a] -> Int`
myLength :: (Num a) => [t] -> a
myLength [] = 0
myLength (_:xs) = 1 + myLength xs
mySum :: (Num a) => [a] -> a
mySum [] = 0
mySum (x:xs) = x + (mySum xs)
mean :: Fractional a => [a] -> Maybe a
mean :: Fractional a => [a] -> Maybe a
mean [] = Nothing
mean xs = Just (sum / len)
where sum = mySum xs
len = myLength xs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment