Skip to content

Instantly share code, notes, and snippets.

@vastus
Created May 6, 2018 18:25
Show Gist options
  • Select an option

  • Save vastus/fa1cb2d756fc689ad6a5bdb284bae60c to your computer and use it in GitHub Desktop.

Select an option

Save vastus/fa1cb2d756fc689ad6a5bdb284bae60c to your computer and use it in GitHub Desktop.
lengthAndSum :: [Int] -> State Int Int
lengthAndSum [] = return 0
lengthAndSum (x:xs) = do
let (len, sum) = runState (lengthAndSum xs) x
put (sum + x)
return (len + 1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment