On Feb 5, 2010, at 12:34 , Aran Donohue wrote:
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.

Hm.  Does it make sense to make this a Functor?

> instance Functor Binding where
>   fmap f (Binding v e) = Binding v (f e)

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com
system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu
electrical and computer engineering, carnegie mellon university    KF8NH