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

empty constructor with alternative #8

Closed
pacak opened this issue Jun 15, 2019 · 4 comments
Closed

empty constructor with alternative #8

pacak opened this issue Jun 15, 2019 · 4 comments

Comments

@pacak
Copy link

pacak commented Jun 15, 2019

As documentation explains you can create something out of nothing using mempty, which imposes a Monoid constraint on every field which rules out a whole bunch of useful types.

An alternative would be to impose constraint on functor - Alternative f can provide "something" filled with "nothing"

data Foo = Foo Int deriving Generic

nofoo :: Alternative f => HKD Foo f
nofoo = bmap (const empty) (deconstruct (Foo undefined) :: HKD Foo (Const ()))

nofoo can be for example Foo Nothing or Foo (Left "")

@i-am-tom
Copy link
Owner

Aha! There's actually a function in the Barbies library, buniq that does exactly this. I think this could certainly lead to some more useful examples, though I'd agree that Alternative would be a nice addition to the library :)

@pacak
Copy link
Author

pacak commented Jun 17, 2019

Hmm... True, nofoo = buniq empty. Feel free to close. Might make sense to add this into readme.

@i-am-tom
Copy link
Owner

Agreed - I'll leave it open until I make the change, if that's cool :)

@i-am-tom
Copy link
Owner

Added an example in the README :)

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

2 participants