<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">After struggled this far, I decide that I can neither trivially understand `pattern TypeRep`, nor the `withTypeable` at core. But this is what really amazing with Haskell, GHC and the community here - I can get my job done even without full understanding of what's going on under the hood, so long as the compiler says it's okay! The warning has gone due to unknown reason after I refactored the code a bit, surprisingly but well, I feel safe and comfort to use it now.</div><div class=""><br class=""></div><div class="">Thanks to Erik, Vlad and Jaro again for your help.</div><div class=""><br class=""></div><div class="">u/Iceland_jack made a ticket to [add pattern TypeRep to Type.Reflection](<a href="https://gitlab.haskell.org/ghc/ghc/-/issues/19691" class="">https://gitlab.haskell.org/ghc/ghc/-/issues/19691</a>) and appears it's very welcomed. Though I don't expect it get shipped very soon or even could be back ported to GHC 8.8, so I end up with this shim:</div><div class=""><br class=""></div><div class="">(there `PolyKinds` appears some unusual to be put into my `.cabal` due to its syntax change can break some of my existing code)</div><div class=""><br class=""></div><div class="">```hs</div><div class=""><div style="color: rgb(212, 190, 152); background-color: rgb(23, 24, 24); font-family: Menlo, Monaco, "Courier New", monospace; line-height: 18px; white-space: pre;" class=""><div class=""><span style="color: #9b84da;" class="">{-# </span><span style="color: #9b84da;font-weight: bold;" class="">LANGUAGE</span><span style="color: #9b84da;" class=""> </span><span style="color: #9b84da;text-decoration: underline;" class="">PolyKinds</span><span style="color: #9b84da;" class=""> #-}</span></div><br class=""><div class=""><span style="color: #cc524b;" class="">module</span><span style="color: #73a36c;" class=""> Dyn.Shim</span></div><div class=""><span style="color: #73a36c;" class=""> </span>(<span style="color: #73a36c;" class=""> </span><span style="color: #cc524b;" class="">pattern</span><span style="color: #73a36c;" class=""> </span><span style="color: #cca143;" class="">TypeRep</span>,</div><div class=""><span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">dynPerformIO</span>,</div><div class=""><span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">dynPerformSTM</span>,</div><div class=""><span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">dynContSTM</span>,</div><div class=""><span style="color: #73a36c;" class=""> </span>)</div><div class=""><span style="color: #cc524b;" class="">where</span></div><br class=""><div class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Control.Concurrent.STM </span>(<span style="color: #6b95c5;" class="">STM</span>)</div><div class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Data.Dynamic </span>(<span style="color: #6b95c5;" class="">Dynamic</span><span style="color: #73a36c;" class=""> </span>(<span style="color: #cca143;" class="">..</span>),<span style="color: #73a36c;" class=""> </span><span style="color: #6b95c5;" class="">Typeable</span>)</div><div class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Type.Reflection</span></div><div class=""><span style="color: #73a36c;" class=""> </span>(<span style="color: #73a36c;" class=""> </span><span style="color: #6b95c5;" class="">TypeRep</span>,</div><div class=""><span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">eqTypeRep</span>,</div><div class=""><span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">typeRep</span>,</div><div class=""><span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">withTypeable</span>,</div><div class=""><span style="color: #73a36c;" class=""> </span><span style="color: #cc524b;" class="">pattern</span><span style="color: #73a36c;" class=""> </span><span style="color: #cca143;" class="">App</span>,</div><div class=""><span style="color: #73a36c;" class=""> </span><span style="color: #cc524b;" class="">type</span><span style="color: #73a36c;" class=""> </span>(<span style="color: #6b95c5;" class="">:~~:</span>)<span style="color: #73a36c;" class=""> </span>(<span style="color: #6b95c5;" class="">HRefl</span>),</div><div class=""><span style="color: #73a36c;" class=""> </span>)</div><div class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Prelude</span></div><br class=""><div class=""><span style="color: #cc524b;" class="">data</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">TypeableInstance</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">a</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TypeableInstance</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Typeable</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">a</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">TypeableInstance</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">a</span></div><br class=""><div class=""><span style="color: #66a89d;" class="">typeableInstance</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">TypeRep</span><span style="color: #96b946;" class=""> </span><span style="color: #82aed8;" class="">a</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">TypeableInstance</span><span style="color: #96b946;" class=""> </span><span style="color: #82aed8;" class="">a</span></div><div class=""><span style="color: #d4bfa0;" class="">typeableInstance tr </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> withTypeable tr </span><span style="color: #cca143;" class="">TypeableInstance</span></div><br class=""><div class=""><span style="color: #7e6b5f;" class="">{- ORMOLU_DISABLE -}</span></div><br class=""><div class=""><span style="color: #7e6b5f;" class="">-- | Shim for the proposed one at:</span></div><div class=""><span style="color: #7e6b5f;" class="">-- <a href="https://gitlab.haskell.org/ghc/ghc/-/issues/19691" class="">https://gitlab.haskell.org/ghc/ghc/-/issues/19691</a></span></div><div class=""><span style="color: #cc524b;" class="">pattern</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-style: italic;" class="">forall</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">k</span><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #82aed8;" class="">a</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">k</span>)<span style="color: #cc524b;font-weight: bold;" class="">.</span><span style="color: #d4bfa0;" class=""> </span>()<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Typeable</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">a</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">a</span></div><div class=""><span style="color: #cc524b;" class="">pattern</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class=""><-</span><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #d4bfa0;" class="">typeableInstance </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TypeableInstance</span>)</div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> typeRep</span></div><br class=""><div class=""><span style="color: #7e6b5f;" class="">{- ORMOLU_ENABLE -}</span></div><br class=""><div class=""><span style="color: #7e6b5f;" class="">-- | Perform a polymorphic IO action which is wrapped in a 'Dynamic'</span></div><div class=""><span style="color: #7e6b5f;" class="">--</span></div><div class=""><span style="color: #7e6b5f;" class="">-- The specified 'naAlt' action will be performed instead, if the wrapped</span></div><div class=""><span style="color: #7e6b5f;" class="">-- computation is not applicable, i.e. not really an IO action.</span></div><div class=""><span style="color: #66a89d;" class="">dynPerformIO</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Dynamic</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Dynamic</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Dynamic</span></div><div class=""><span style="color: #d4bfa0;" class="">dynPerformIO naAlt </span>(<span style="color: #cca143;" class="">Dynamic</span><span style="color: #d4bfa0;" class=""> trAct monotypedAct</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> trAct </span><span style="color: #cc524b;" class="">of</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">App</span><span style="color: #d4bfa0;" class=""> io </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> io </span><span style="color: #96b946;font-weight: bold;" class="">`</span><span style="color: #96b946;" class="">eqTypeRep</span><span style="color: #96b946;font-weight: bold;" class="">`</span><span style="color: #d4bfa0;" class=""> typeRep </span><span style="color: #b3ddf5;" class="">@</span><span style="color: #6b95c5;" class="">IO</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">of</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">HRefl</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Dynamic</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class=""><$></span><span style="color: #d4bfa0;" class=""> monotypedAct</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Nothing</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> naAlt </span><span style="color: #7e6b5f;" class="">-- not an IO action</span></div><div class=""><span style="color: #d4bfa0;" class=""> _ </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> naAlt </span><span style="color: #7e6b5f;" class="">-- not even a poly-type</span></div><br class=""><div class=""><span style="color: #7e6b5f;" class="">-- | Perform a polymorphic STM action which is wrapped in a 'Dynamic'</span></div><div class=""><span style="color: #7e6b5f;" class="">--</span></div><div class=""><span style="color: #7e6b5f;" class="">-- The specified 'naAlt' action will be performed instead, if the wrapped</span></div><div class=""><span style="color: #7e6b5f;" class="">-- computation is not applicable, i.e. not really an STM action.</span></div><div class=""><span style="color: #66a89d;" class="">dynPerformSTM</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">STM</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Dynamic</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Dynamic</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">STM</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Dynamic</span></div><div class=""><span style="color: #d4bfa0;" class="">dynPerformSTM naAlt </span>(<span style="color: #cca143;" class="">Dynamic</span><span style="color: #d4bfa0;" class=""> trAct monotypedAct</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> trAct </span><span style="color: #cc524b;" class="">of</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">App</span><span style="color: #d4bfa0;" class=""> io </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> io </span><span style="color: #96b946;font-weight: bold;" class="">`</span><span style="color: #96b946;" class="">eqTypeRep</span><span style="color: #96b946;font-weight: bold;" class="">`</span><span style="color: #d4bfa0;" class=""> typeRep </span><span style="color: #b3ddf5;" class="">@</span><span style="color: #6b95c5;" class="">STM</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">of</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">HRefl</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Dynamic</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class=""><$></span><span style="color: #d4bfa0;" class=""> monotypedAct</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Nothing</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> naAlt </span><span style="color: #7e6b5f;" class="">-- not an STM action</span></div><div class=""><span style="color: #d4bfa0;" class=""> _ </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> naAlt </span><span style="color: #7e6b5f;" class="">-- not even a poly-type</span></div><br class=""><div class=""><span style="color: #7e6b5f;" class="">-- | Perform a polymorphic STM action which is wrapped in a 'Dynamic'</span></div><div class=""><span style="color: #7e6b5f;" class="">--</span></div><div class=""><span style="color: #7e6b5f;" class="">-- The specified 'naAlt' action will be performed instead, if the wrapped</span></div><div class=""><span style="color: #7e6b5f;" class="">-- computation is not applicable, i.e. not really an STM action.</span></div><div class=""><span style="color: #66a89d;" class="">dynContSTM</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">STM</span><span style="color: #96b946;" class=""> </span>()<span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Dynamic</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span>(<span style="color: #6b95c5;" class="">Dynamic</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">STM</span><span style="color: #96b946;" class=""> </span>())<span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">STM</span><span style="color: #96b946;" class=""> </span>()</div><div class=""><span style="color: #d4bfa0;" class="">dynContSTM naAlt </span>(<span style="color: #cca143;" class="">Dynamic</span><span style="color: #d4bfa0;" class=""> trAct monotypedAct</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">exit </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> trAct </span><span style="color: #cc524b;" class="">of</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">App</span><span style="color: #d4bfa0;" class=""> io </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> io </span><span style="color: #96b946;font-weight: bold;" class="">`</span><span style="color: #96b946;" class="">eqTypeRep</span><span style="color: #96b946;font-weight: bold;" class="">`</span><span style="color: #d4bfa0;" class=""> typeRep </span><span style="color: #b3ddf5;" class="">@</span><span style="color: #6b95c5;" class="">STM</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">of</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">HRefl</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> exit </span><span style="color: #a3d349;" class="">.</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Dynamic</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class="">=<<</span><span style="color: #d4bfa0;" class=""> monotypedAct</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Nothing</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> naAlt </span><span style="color: #7e6b5f;" class="">-- not an STM action</span></div><div class=""><span style="color: #d4bfa0;" class=""> _ </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> naAlt </span><span style="color: #7e6b5f;" class="">-- not even a poly-type</span></div><br class=""></div></div><div class="">```</div><div class=""><br class=""></div><div class="">And my test case being a little more complex than the very first example, might be easier for others to grasp the usage, it runs like this:</div><div class=""><br class=""></div><div class="">```console</div><div class=""><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #5a23f9" class="">λ> </span><span style="font-variant-ligatures: no-common-ligatures" class="">import PoC.DynPoly</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #5a23f9" class="">λ> </span><span style="font-variant-ligatures: no-common-ligatures" class="">testDynHold </span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">First got Nothing</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(116, 229, 202); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">Then got Just 3</span></div><div style="margin: 0px; font-stretch: normal; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(90, 35, 249); background-color: rgb(22, 27, 24);" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">λ> </span></div></div><div class="">```</div><div class=""><br class=""></div><div class="">With the code:</div><div class=""><br class=""></div><div class="">```hs</div><div class=""><div style="color: rgb(212, 190, 152); background-color: rgb(23, 24, 24); font-family: Menlo, Monaco, "Courier New", monospace; line-height: 18px; white-space: pre;" class=""><div class=""><span style="color: #cc524b;" class="">module</span><span style="color: #73a36c;" class=""> PoC.DynPoly </span><span style="color: #cc524b;" class="">where</span></div><br class=""><div class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Control.Monad </span>(<span style="color: #66a89d;" class="">void</span>)</div><div class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Data.Dynamic </span>(<span style="color: #6b95c5;" class="">Dynamic</span><span style="color: #73a36c;" class=""> </span>(<span style="color: #cca143;" class="">..</span>),<span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">fromDynamic</span>,<span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">toDyn</span>)</div><div class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Data.IORef </span>(<span style="color: #66a89d;" class="">modifyIORef'</span>,<span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">newIORef</span>,<span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">readIORef</span>,<span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">writeIORef</span>)</div><div class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Dyn.Shim</span></div><div class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Type.Reflection </span>(<span style="color: #66a89d;" class="">eqTypeRep</span>,<span style="color: #73a36c;" class=""> </span><span style="color: #66a89d;" class="">typeRep</span>,<span style="color: #73a36c;" class=""> </span><span style="color: #cc524b;" class="">pattern</span><span style="color: #73a36c;" class=""> </span><span style="color: #cca143;" class="">App</span>,<span style="color: #73a36c;" class=""> </span><span style="color: #cc524b;" class="">type</span><span style="color: #73a36c;" class=""> </span>(<span style="color: #6b95c5;" class="">:~~:</span>)<span style="color: #73a36c;" class=""> </span>(<span style="color: #6b95c5;" class="">HRefl</span>))</div><div class=""><span style="color: #cc524b;" class="">import</span><span style="color: #73a36c;" class=""> Prelude</span></div><br class=""><div class=""><span style="color: #66a89d;" class="">dynHoldEvent</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Dynamic</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">Dynamic</span></div><div class=""><span style="color: #d4bfa0;" class="">dynHoldEvent </span>(<span style="color: #cca143;" class="">Dynamic</span><span style="color: #d4bfa0;" class=""> trEvs monotypedEvs</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> trEvs </span><span style="color: #cc524b;" class="">of</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">App</span><span style="color: #d4bfa0;" class=""> trEs </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> trEs </span><span style="color: #96b946;font-weight: bold;" class="">`</span><span style="color: #96b946;" class="">eqTypeRep</span><span style="color: #96b946;font-weight: bold;" class="">`</span><span style="color: #d4bfa0;" class=""> typeRep </span><span style="color: #b3ddf5;" class="">@</span><span style="color: #6b95c5;" class="">EventSink</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">of</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">HRefl</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Dynamic</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TypeRep</span><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #d4bfa0;" class="">holdEvent monotypedEvs</span>)</div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Nothing</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #97a2a7;" class="">"not an EventSink"</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #7e6b5f;" class="">-- to be handled properly</span></div><div class=""><span style="color: #d4bfa0;" class=""> _ </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #97a2a7;" class="">"even not a poly-type"</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #7e6b5f;" class="">-- to be handled properly</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span></div><div class=""><span style="color: #96b946;" class=""> </span><span style="color: #66a89d;" class="">holdEvent</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-style: italic;" class="">forall</span><span style="color: #96b946;" class=""> </span><span style="color: #82aed8;" class="">a</span><span style="color: #cc524b;font-weight: bold;" class="">.</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">EventSink</span><span style="color: #96b946;" class=""> </span><span style="color: #82aed8;" class="">a</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #96b946;" class=""> </span>(<span style="color: #6b95c5;" class="">TimeSeries</span><span style="color: #96b946;" class=""> </span><span style="color: #82aed8;" class="">a</span>)</div><div class=""><span style="color: #d4bfa0;" class=""> holdEvent </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">evs </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">do</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">holder </span><span style="color: #cc524b;font-weight: bold;" class=""><-</span><span style="color: #d4bfa0;" class=""> newIORef </span><span style="color: #cca143;" class="">Nothing</span></div><div class=""><span style="color: #d4bfa0;" class=""> listenEvents evs </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> writeIORef holder </span><span style="color: #a3d349;" class="">.</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just</span></div><div class=""><span style="color: #d4bfa0;" class=""> return </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TimeSeries</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> readIORef holder</span></div><br class=""><div class=""><span style="color: #cc524b;" class="">data</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">EventSink</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">a</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">EventSink</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">{</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">listenEvents</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #82aed8;" class="">a</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #d4bfa0;" class=""> </span>())<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #d4bfa0;" class=""> </span>(),</div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">publishEvent</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">a</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #d4bfa0;" class=""> </span>()</div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">}</span></div><br class=""><div class=""><span style="color: #cc524b;" class="">newtype</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">TimeSeries</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">a</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">TimeSeries</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">{readTimeSeries</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #6b95c5;" class="">Maybe</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #82aed8;" class="">a</span>)<span style="color: #cca143;" class="">}</span></div><br class=""><div class=""><span style="color: #66a89d;" class="">newEventSink</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-style: italic;" class="">forall</span><span style="color: #96b946;" class=""> </span><span style="color: #82aed8;" class="">a</span><span style="color: #cc524b;font-weight: bold;" class="">.</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #96b946;" class=""> </span>(<span style="color: #6b95c5;" class="">EventSink</span><span style="color: #96b946;" class=""> </span><span style="color: #82aed8;" class="">a</span>)</div><div class=""><span style="color: #d4bfa0;" class="">newEventSink </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">do</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">listeners </span><span style="color: #cc524b;font-weight: bold;" class=""><-</span><span style="color: #d4bfa0;" class=""> newIORef </span>[]</div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">let</span><span style="color: #d4bfa0;" class=""> listen listener </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> modifyIORef' listeners </span>(<span style="color: #d4bfa0;" class="">listener </span><span style="color: #cca143;" class="">:</span>)</div><div class=""><span style="color: #d4bfa0;" class=""> publish a </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> readIORef listeners </span><span style="color: #a3d349;" class="">>>=</span><span style="color: #d4bfa0;" class=""> void </span><span style="color: #a3d349;" class="">.</span><span style="color: #d4bfa0;" class=""> mapM </span>(<span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> a</span>)</div><div class=""><span style="color: #d4bfa0;" class=""> return </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">EventSink</span><span style="color: #d4bfa0;" class=""> listen publish</span></div><br class=""><div class=""><span style="color: #66a89d;" class="">testDynHold</span><span style="color: #96b946;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #96b946;" class=""> </span><span style="color: #6b95c5;" class="">IO</span><span style="color: #96b946;" class=""> </span>()</div><div class=""><span style="color: #d4bfa0;" class="">testDynHold </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">do</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #d4bfa0;" class="">evs </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">EventSink</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Int</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class=""><-</span><span style="color: #d4bfa0;" class=""> newEventSink</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">let</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">dynEvs </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> toDyn evs</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">dynHold </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> dynHoldEvent dynEvs</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">dynTs </span><span style="color: #cc524b;font-weight: bold;" class=""><-</span><span style="color: #d4bfa0;" class=""> dynPerformIO </span>(<span style="color: #d4bfa0;" class="">error </span><span style="color: #97a2a7;" class="">"bug: dyn type mismatch?"</span>)<span style="color: #d4bfa0;" class=""> dynHold</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">case</span><span style="color: #d4bfa0;" class=""> fromDynamic dynTs </span><span style="color: #cc524b;" class="">of</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Nothing</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> error </span><span style="color: #97a2a7;" class="">"bug: unexpected dyn result type"</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Just</span><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #d4bfa0;" class="">ts </span><span style="color: #cc524b;font-weight: bold;" class="">::</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">TimeSeries</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Int</span>)<span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;font-weight: bold;" class="">-></span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">do</span></div><div class=""><span style="color: #d4bfa0;" class=""> v0 </span><span style="color: #cc524b;font-weight: bold;" class=""><-</span><span style="color: #d4bfa0;" class=""> readTimeSeries ts</span></div><div class=""><span style="color: #d4bfa0;" class=""> putStrLn </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"First got "</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class=""><></span><span style="color: #d4bfa0;" class=""> show v0</span></div><div class=""><span style="color: #d4bfa0;" class=""> publishEvent evs </span><span style="color: #97a2a7;" class="">3</span></div><div class=""><span style="color: #d4bfa0;" class=""> v1 </span><span style="color: #cc524b;font-weight: bold;" class=""><-</span><span style="color: #d4bfa0;" class=""> readTimeSeries ts</span></div><div class=""><span style="color: #d4bfa0;" class=""> putStrLn </span><span style="color: #a3d349;" class="">$</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #97a2a7;" class="">"Then got "</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #a3d349;" class=""><></span><span style="color: #d4bfa0;" class=""> show v1</span></div></div></div><div class="">```</div><div class=""><br class=""></div><div class="">Thanks with best regards,</div><div class="">Compl</div><div class=""><br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 2021-04-13, at 02:50, Erik Hesselink <<a href="mailto:hesselink@gmail.com" class="">hesselink@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">That is a lot, I'm not sure I understand that pattern synonym. Using `withTypeable` instead works for me:</div><div class=""><br class=""></div><div class="">holdEvent :: Dynamic -> Dynamic<br class="">holdEvent (Dynamic tr x) =<br class=""> case tr of<br class=""> App ft at -><br class=""> case ft `eqTypeRep` typeRep @EventSink of<br class=""> Just HRefl -> withTypeable at $ toDyn (hcHoldEvent x)<br class=""> Nothing -> error "to handle"<br class=""> _ -> error "to handle"</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Erik<br class=""></div></div></div></blockquote></div><br class=""></div></body></html>