Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a reason Exception and Maybe don't implement Bifunctor? #170

Closed
mattly opened this issue May 3, 2016 · 3 comments
Closed

Is there a reason Exception and Maybe don't implement Bifunctor? #170

mattly opened this issue May 3, 2016 · 3 comments

Comments

@mattly
Copy link

mattly commented May 3, 2016

Perhaps I'm misunderstanding Monadic laws or the like, but I've hit a situation where it would be useful to bimap over an Exception or Maybe monad without necessarily knowing which type it is, and it seems only Either implements the Bifunctor protocol. Is this for Category Theory reasons or simply an omission?

@yurrriq
Copy link
Collaborator

yurrriq commented May 3, 2016

I wasn't able to find any good resources online quickly, but as I understand it, a Bifunctor instance for Exception or Maybe doesn't make sense, because unlike Either or Pair, there's no "left" value to map over.

Nothing represents the absence of a value and Exception represents an error, thus not a desirable value. Therefore it doesn't make sense to want to map over them.

@yurrriq
Copy link
Collaborator

yurrriq commented May 3, 2016

If you look at Data.Bifunctor:

Bifunctor Either
Bifunctor (,)
Bifunctor Const
Bifunctor ((,,) x1)
Bifunctor ((,,,) x1 x2)
Bifunctor ((,,,,) x1 x2 x3)
Bifunctor ((,,,,,) x1 x2 x3 x4)
Bifunctor ((,,,,,,) x1 x2 x3 x4 x5)

We've got instances for cats.data.Pair and cats.monad.Either, but maybe it'd be cool to do clojure.lang.PersistentVector or some other seqs too.

@niwinz
Copy link
Member

niwinz commented Jun 16, 2016

I agree with @yurrriq

@niwinz niwinz closed this as completed Jun 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants