i-am-tom/higgledy

empty constructor with alternative

pacak opened this issue · 4 comments

pacak commented

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 "")

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 commented

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

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

Added an example in the README :)