Availability of Coercible Instances at TH Runtime

Travis Whitaker pi.boy.travis at gmail.com
Sat May 5 02:01:43 UTC 2018

A workaround that's suitable for what I'm after is defining a class like
this for some fixed T.

instance (Coercible a T) => C a

I'm curious what it'd take to add a qReifyCoercible method; does the
renamer know anything about Coercible?


On Fri, May 4, 2018 at 11:01 AM, Richard Eisenberg <rae at cs.brynmawr.edu>

> I don't think there's an easy way to do this. We could imagine extending
> Quasi to have a method to check for coercibility, but I don't think there's
> a way to do this in the current TH API. Sorry!
> Richard
> On May 4, 2018, at 3:44 AM, Travis Whitaker <pi.boy.travis at gmail.com>
> wrote:
> Given that Coercible instances are Deeply Magical, perhaps I'm being a bit
> naive here, but I recently tried to write a TH function that can check if
> one type is a newtype of another (or a newtype of a newtype of another,
> etc).
> coercibleToFrom :: Type -> Type -> Q Bool
> coercibleToFrom tx ty = (&&) <$> isInstance ''Coercible [tx, ty]
>                              <*> isInstance ''Coercible [ty, tx]
> If this worked as I'd hoped, I'm almost certain checking reflexively is
> redundant. However, I can't seem to get reifyInstances to ever return an
> InstanceDec for a Coercible instance. Given that these instances are
> generated on the fly by the typechecker, there's no way to make them
> available at TH runtime, correct? And, given that, is there an easy way to
> find out with TH whether not I'll be able to use coerce without taking all
> the Decs apart to hunt for NewtypeD?
> Travis
> _______________________________________________
> ghc-devs mailing list
> ghc-devs at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-devs/attachments/20180504/83fcf4aa/attachment.html>

More information about the ghc-devs mailing list