<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">The problem is in the reify function:</div><div class=""><br class=""></div><div class="">```</div><div class=""><div class="">reify :: forall a r. a -> (forall (s :: *). Reifies s a => Proxy s -> r) -> r</div><div class="">reify a k = unsafeCoerce (Magic k :: Magic a r) (const a) Proxy</div></div><div class="">```</div><div class="">here, unsafeCoerce coerces `const a` to type `a`, in the concrete case, to Int.</div><div class="">```</div><div class="">*Main> unsafeCoerce (const 5) :: Int</div><div class="">1099511628032</div><div class="">```</div><div class="">this is indeed what seems to be the issue:</div><div class="">```</div><div class="">*Main> reify 5 reflect</div><div class="">1099511628032</div><div class="">```</div><div class="">which is why test1 then shows the wrong result.</div><div class=""><br class=""></div><div class="">Also, in the Magic newtype, there’s a `Proxy s`, which afaik doesn’t have the expected runtime representation</div><div class="">`a -> r`. (there’s a proxy in the middle, `a -> Proxy -> r`).</div><div class=""><br class=""></div><div class="">Changing Magic to</div><div class="">```</div><div class=""><div class="">newtype Magic a r = Magic (forall (s :: *) . Reifies s a => Tagged s r)</div></div><div class="">```</div><div class="">now has the correct runtime rep, and the reification can be done by coercing the Magic in to `a -> r`, as such</div><div class="">```</div><div class=""><div class="">reify' :: a -> (forall (s :: *) . Reifies s a => Tagged s r) -> r</div><div class="">reify' a f = unsafeCoerce (Magic f) a</div></div><div class="">```</div><div class=""><br class=""></div><div class="">the Proxy version is just a convenience, wrapped around the magic one:</div><div class=""><br class=""></div><div class="">```</div><div class=""><div class="">reify :: forall r a. a -> (forall (s :: *) . Reifies s a => Proxy s -> r) -> r</div><div class="">reify a f = reify' a (unproxy f)</div></div><div class="">```</div><div class=""><br class=""></div><div class="">Here’s the complete file, with the changes that compile and now work:</div><div class=""><br class=""></div><div class=""><a href="https://gist.github.com/kcsongor/b2f829b2b60022505b7e48b1360d2679" class="">https://gist.github.com/kcsongor/b2f829b2b60022505b7e48b1360d2679</a></div><div class=""><br class=""></div><div class="">— Csongor</div><br class=""><div><blockquote type="cite" class=""><div class="">On 20 Jan 2017, at 14:14, Matthew Pickering <<a href="mailto:matthewtpickering@gmail.com" class="">matthewtpickering@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">I modified the example on the wiki to compile but I seem to have<br class="">missed something, could you perhaps point out what I missed?<br class=""><br class=""><a href="https://gist.github.com/mpickering/da6d7852af2f6c8f59f80ce726baa864" class="">https://gist.github.com/mpickering/da6d7852af2f6c8f59f80ce726baa864</a><br class=""><br class="">```<br class="">*Main> test1 2 123 441212<br class="">441335<br class="">```<br class=""><br class="">On Thu, Jan 19, 2017 at 3:58 AM, David Feuer <david@well-typed.com> wrote:<br class=""><blockquote type="cite" class="">I've updated https://ghc.haskell.org/trac/ghc/wiki/MagicalReflectionSupport to<br class="">reflect both Simon's thoughts on the matter and my own reactions to them. I<br class="">hope you'll give it a peek.<br class=""><br class="">David Feuer<br class="">_______________________________________________<br class="">ghc-devs mailing list<br class="">ghc-devs@haskell.org<br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs<br class=""></blockquote>_______________________________________________<br class="">ghc-devs mailing list<br class="">ghc-devs@haskell.org<br class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs<br class=""></div></div></blockquote></div><br class=""></body></html>