
Am Dienstag 01 Dezember 2009 21:00:13 schrieb Daniel Fischer:
Am Dienstag 01 Dezember 2009 20:21:27 schrieb Evan Laforge:
This is only peripherally related, but I also have a lot of list functions that can possibly be an error, but usually processing can continue. So they tend to return [Either Error Result]. I have another function thus:
-- A foldr version is not lazy enough and overflows the stack.
try
foldr (\e ~(ls,rs) -> case e of { Left l -> (l:ls,rs); Right r -> (ls,r:rs) }) ([],[])
with the lazy pattern, it should be lazy enough.
Yup. Tested now.
partition_either [] = ([], []) partition_either (x:xs) = let (ls, rs) = partition_either xs in case x of Left l -> (l:ls, rs) Right r -> (ls, r:rs)
I was a little surprised I couldn't find this in the standard library... or maybe it is?
Data.Either.partitionEithers
And that's not lazy enough, either. Ticket: http://hackage.haskell.org/trac/ghc/ticket/3709
Data.List.partition isLeft
isLeft (Left _) = True isLeft _ = False
Not quite the same.