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

Add instances for Nothing #2778

Open
julien-truffaut opened this issue Apr 8, 2019 · 5 comments
Open

Add instances for Nothing #2778

julien-truffaut opened this issue Apr 8, 2019 · 5 comments

Comments

@julien-truffaut
Copy link
Contributor

What do you think about adding instances for Nothing like Eq, Ord, Semigroup?

I can submit a PR

@kailuowang
Copy link
Contributor

Are you proposing adding them to alleycats or cats.core? I am asking because it seems to me that they have to be lawless instances right?

@LukaJCB
Copy link
Member

LukaJCB commented Apr 8, 2019

@milessabin
Copy link
Member

What's the motivation? I'd be worried that those instances would increase the chances of unwanted nothings being inferred.

@julien-truffaut
Copy link
Contributor Author

@kailuowang to cats.core, I believe they are completely legit since you can't ever produce a value of typeNothing.

@milessabin mainly because it is possible and Nothing is an important part of type theory. I am aware the compiler treats Nothing a bit differently but I can't tell if it would create any issue. I can think of some contrived examples where it could be used:

def foo[A: Eq](xs: List[A], ys: List[A]): Option[A] =
  if(xs === ys) xs.headOption
  else None

foo(Nil, Nil)

@nigredo-tori
Copy link
Contributor

These can be useful for tests. E.g. in ZIO when creating an abstraction like class Foo[E, A: Eq](action: IO[E, A]), it is useful to test the cases when the action fails by passing in something like ZIO.fail("error"). Nothing pops up naturally here.

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

5 participants