[Haskell-cafe] a beginner question: decorate-op-undecorate
aran.donohue at gmail.com
Fri Feb 5 12:34:01 EST 2010
Consider a data type such as
data Binding = Binding Var (Either Value [Value])
representing a variable bound either to a fixed value or that has a list of
I'd like to perform an operation on say, the fixed-value members of a list
of bindings. Data.Either has "partitionEithers"---I'd essentially like to
use partitionEithers, but in a way that it "peeks" into the value field of
the binding. For the sake of argument, let's say I can't or can't modify
Binding to move the Either to the outside.
What would be an idiomatic Haskell way to accomplish this? Currently I've
got "liftedPartitionEithers :: [a] -> (a -> Either b c) -> ([a], [a])" which
is my own version of partitionEithers that calls a selector first. Another
option would be to map each Binding to a new datatype that has the Either on
the outside, use partitionEithers, and map back.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe