Skip to content

second/right derived from first/left #49

@erykciepiela

Description

@erykciepiela

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions