Last active
December 15, 2015 19:03
-
-
Save charles-cooper/153a539617a3fd01a31b 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
nan = 0/0 | |
silenceNaN d = if isNaN d then 0 else d | |
cumSumWithMissing :: [Double] -> [Double] | |
cumSumWithMissing ds = let | |
ret = scanl1 (+) $ silenceNaN <$> ds | |
go x y = if isNaN x then x else y | |
in zipWith go ds ret | |
foo :: [Double] -> [Double] | |
foo ds = let | |
go x y = if isNaN x then x else y | |
in zipWith go ds $ silenceNaN <$> ds | |
main = do | |
print $ foo [1,2,nan,3] | |
print $ cumSumWithMissing [1,2,nan,3] |
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
$ runghc foo.hs | |
[1.0,2.0,NaN,3.0] | |
[1.0,3.0,NaN,6.0] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment