Created
November 19, 2013 10:54
-
-
Save bananu7/7543670 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
import Control.Monad.State | |
type Count = Int | |
--type Sum = Int | |
type MyState = State Count | |
n :: Float -> Float -> MyState Float | |
n x s = do | |
c <- get | |
let c' = c+1 | |
put c' | |
return $ (x+s) | |
end :: Float -> MyState Float | |
end s = do | |
c <- get | |
return $ s / (fromIntegral c :: Float) | |
fun = (return 0.0) >>= (n 3.0) >>= (n 4.0) >>= (n 5.0) >>= (n 6.0) >>= end | |
avg = runState fun 0 | |
main = print $ avg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment