Skip to content

Instantly share code, notes, and snippets.

@dmwit
Created July 21, 2019 21:39
Show Gist options
  • Save dmwit/fe96f4a2ac769029e57f0019d642c34c to your computer and use it in GitHub Desktop.
Save dmwit/fe96f4a2ac769029e57f0019d642c34c to your computer and use it in GitHub Desktop.
sums :: Num a => [a] -> (a, [a])
sums [] = (0, [])
sums (x:xs) = let ~(v,vs) = sums xs; v' = v+x in v' `seq` (v',v':vs)
main :: IO ()
main = print (fst (sums [0..1000000 :: Int]))
-- OR
-- main = print (last (scanl1 (+) [0..1000000 :: Int]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment