[Haskell-cafe] a beginner question: decorate-op-undecorate

Felipe Lessa felipe.lessa at gmail.com
Fri Feb 5 12:49:59 EST 2010

On Fri, Feb 05, 2010 at 12:34:01PM -0500, Aran Donohue wrote:
> Hi Haskell-Cafe,
> 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
> possible values.
> 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.
> Thanks,
> Aran

> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

You could try using uniplate[1], something like

    transformBi (either doWhatYouLike id)

I guess :).

[1] http://hackage.haskell.org/package/uniplate


More information about the Haskell-Cafe mailing list