quickspec icon indicating copy to clipboard operation
quickspec copied to clipboard

Delimited defaultTo

Open isovector opened this issue 4 years ago • 0 comments

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.

isovector avatar Aug 19 '20 13:08 isovector