Last active
December 31, 2015 20:19
-
-
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`
This file contains hidden or 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
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