Created
July 21, 2019 21:39
-
-
Save dmwit/fe96f4a2ac769029e57f0019d642c34c to your computer and use it in GitHub Desktop.
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
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