Skip to content

Instantly share code, notes, and snippets.

@bananu7
Created November 19, 2013 10:54
Show Gist options
  • Save bananu7/7543670 to your computer and use it in GitHub Desktop.
Save bananu7/7543670 to your computer and use it in GitHub Desktop.
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