sorear | note that if the list is used once, ghc can fuse the consumer and producer |

yshhq | but still i think my question is that difficult |

ndm | sorear, fusion would probably eliminate the list totally, and be much faster than bytestring |

sorear | ndm: not if there are multiple consumption loops |

yshhq | since to calculate sum(x) you need to calculate partial sum so it should be able to stop in the middle if I only want to test sum(x) == n because of laziness, right? |

dmwit | yshhq: Take a look at scanl, dropWhile, and null. Some combination of those should get you what you want. |

yshhq | 3x |

dmwit | > [1..] == [1] |

lambdabot | False |

dmwit | Probably don't even need null, come to think of it. > let checkSum n xs = [n] == dropWhile (< n) $ scanl1 (+) xs in checkSum 55 [1..10] |

lambdabot | Couldn't match expected type `[a]' |

dmwit | :t scanl1 |

lambdabot | forall a. (a -> a -> a) -> [a] -> [a] |

dmwit | > let checkSum n xs = [n] == (dropWhile (< n) $ scanl1 (+) xs) in checkSum 55 [1..10] |

lambdabot | True |

dmwit | > let checkSum n xs = [n] == (dropWhile (< n) $ scanl1 (+) xs) in checkSum 54 [1..10] |

lambdabot | False |

dmwit | > let checkSum n xs = [n] == (dropWhile (< n) $ scanl1 (+) xs) in checkSum 56 [1..10] |

lambdabot | False |

dmwit | > let checkSum n xs = [n] == (dropWhile (< n) $ scanl1 (+) xs) in checkSum 56 [1..] |

lambdabot | False |

EvilTerran | might you want "scanl (+) 0 xs" ? |

dmwit | Sure, why not. Seems like he's dealing with some uber-long lists, though, if he's that worried about summing it. |

EvilTerran | might be a "protection from infinite lists" sort of thing. there's no harm in covering the null case, anyway. |

hpaste | dpiponi pasted "I'm so crap I couldn't have invented monads" at http://hpaste.org/1136 |

dpiponi | I still can't find the error. This is going to be so embarassing... |

Cale | I'll have a look |

augustss | error? |

yshhq | how about let runningSum = scanr1 (+) x in if all (<=n) runningSum then head runningSum == n else False |

dmwit | yshhq: IIRC, scanr is exactly the wrong one for your use. |

yshhq | does using scanl or scanr matter here? |

dpiponi | augustss: I've had too many comments that that post has an error for me to ignore them. |

Cale | scanr won't save you any time |

ddarius | > foldM (\x y -> guard (x+y < 10) >> return (x+y)) 0 [1..3] |

lambdabot | add an instance declaration for (Show (m b)) |