Using the function mapEither for multiset’s, I map a MultiSet to a list of two multiset. When f is returing Left the element is inserted in the first Multiset of "list", if f is returning Right the element is inserted in the second MultiSet of "list".
How can I insert in both MultiSet’s the same element at the same time using f. As if I would return Right and Left at the same time.
f:: LocalType-> Either LocalType LocalType
f (Sometype lt) = Left lt -- And Right lt
f lt = Left lt
parRule :: (MultiSet LocalType) -> (MultiSet LocalType)
parRule sequent = do
let list = MultiSet.mapEither f sequent
For reference, I use Data.Multiset package, https://hackage.haskell.org/package/multiset-0.3.4.3/docs/Data-MultiSet.html.
>Solution :
You can use a type like These to capture the ability to return both. You can then use toAscOccurList and fromOccurList (or fromAscOccurList if your function is monotonic) to compute the new MultiSet.