`second`/`right` derived from `first`/`left`
Opened this issue · 1 comments
erykciepiela commented
Is there any reason why Strong/Choice require second/right and not instead derive them from first/left?
secondBasedOnFirst :: forall p a b c. Strong p => p a b -> p (Tuple c a) (Tuple c b)
-- equivalent to `second`?
secondBasedOnFirst = dimap swap swap <<< first
where
swap :: forall x y. Tuple x y -> Tuple y x
swap (Tuple a b) = Tuple b a
rightBasedOnLeft :: forall p a b c. Choice p => p a b -> p (Either c a) (Either c b)
-- equivalent to `right`?
rightBasedOnLeft = dimap flip flip <<< left
where
flip :: forall x y. Either x y -> Either y x
flip (Left a) = Right a
flip (Right b) = Left b
Is this only because of lack of default type class member implementations feature in PureScript or is there any other reason?
garyb commented
Yeah, it's due to the lack of default member implementations. We could add these to the library though, we do that for the similar case for Foldable, Traversable, etc: https://pursuit.purescript.org/packages/purescript-foldable-traversable/docs/Data.Foldable#v:foldrDefault