nick8325 / quickspec

Equational laws for free
BSD 3-Clause "New" or "Revised" License
250 stars 24 forks source link

Delimited defaultTo #67

Open isovector opened 4 years ago

isovector commented 4 years ago

I've been thinking that defaultTo is too blunt of a tool to be effectively wielded. What do you think about changing its type signature to:

defaultTo :: Signature -> proxy a -> Signature

where a becomes the default only within the scope of the signature argument.

I think this might clean up the problems around putting polymorphic constrained constructors into the background, like in #66. We could do something like this:

monoid :: Sig
monoid = background $ defaultTo
  [ con "mempty" $ liftC @(Monoid A) $ mempty @A
  , con "<>"     $ liftC @(Monoid A) $ (<>)   @A
  , instanceOf @(Monoid [Int])
  ] (Proxy @[Int])

I'd be happy to send a PR if you think this is an avenue worth pursuing.