<div dir="ltr"><div>That is a lot, I'm not sure I understand that pattern synonym. Using `withTypeable` instead works for me:</div><div><br></div><div>holdEvent :: Dynamic -> Dynamic<br>holdEvent (Dynamic tr x) =<br>  case tr of<br>    App ft at -><br>      case ft `eqTypeRep` typeRep @EventSink of<br>        Just HRefl -> withTypeable at $ toDyn (hcHoldEvent x)<br>        Nothing -> error "to handle"<br>    _ -> error "to handle"</div><div><br></div><div>Cheers,</div><div><br></div><div>Erik<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 12 Apr 2021 at 18:58, YueCompl <<a href="mailto:compl.yue@icloud.com">compl.yue@icloud.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div style="overflow-wrap: break-word;">Oh, forgot to mention that there is a warning I also don't understand by far:<div><br></div><div>```log</div><div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(251,34,255);background-color:rgb(22,27,24)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(152,244,245)"><b>src/PoC/DynPoly.hs:40:3: </b></span><span style="font-variant-ligatures:no-common-ligatures"><b>warning:</b></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(152,244,245)"><b> [</b></span><span style="font-variant-ligatures:no-common-ligatures"><b>-Woverlapping-patterns</b></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(152,244,245)"><b>]</b></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)"><span style="font-variant-ligatures:no-common-ligatures">    Pattern match has inaccessible right hand side</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)"><span style="font-variant-ligatures:no-common-ligatures">    In a case alternative: Dynamic (App eventSink TypeRep) evs' -> ...</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(207,125,255);background-color:rgb(22,27,24)"><span style="font-variant-ligatures:no-common-ligatures"><b>   |</b></span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(251,34,255);background-color:rgb(22,27,24)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(207,125,255)"><b>40 |</b></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(116,229,202)">   </span><span style="font-variant-ligatures:no-common-ligatures"><b>Dynamic (App eventSink TypeRep) evs' -></b></span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(251,34,255);background-color:rgb(22,27,24)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(207,125,255)"><b>   |</b></span><span style="font-variant-ligatures:no-common-ligatures"><b>   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^...</b></span></div></div><div>```</div><div>I need to work out some extra stuff to test the solution in real case, meanwhile this warning seems worrying ...<br><div><br><blockquote type="cite"><div>On 2021-04-13, at 00:27, YueCompl via ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>> wrote:</div><br><div><div style="overflow-wrap: break-word;">Thanks Erik,<div><br></div><div>With the help <span style="color:rgb(129,131,132);font-family:verdana,arial,helvetica,sans-serif;font-size:x-small;font-variant-ligatures:normal;background-color:rgb(39,39,41)">from </span><span style="color:rgb(129,131,132);font-family:verdana,arial,helvetica,sans-serif;font-size:x-small;font-variant-ligatures:normal;background-color:rgb(39,39,41)"><a href="https://www.reddit.com/user/Iceland_jack" style="text-decoration:none;color:rgb(79,188,255);margin-right:0.5em" target="_blank">Iceland_jack</a><span></span></span><span style="color:rgb(129,131,132);font-family:verdana,arial,helvetica,sans-serif;font-size:x-small;font-variant-ligatures:normal;background-color:rgb(39,39,41)"> via </span><span style="margin-bottom:10px;color:rgb(129,131,132);font-family:verdana,arial,helvetica,sans-serif;font-size:x-small;font-variant-ligatures:normal;background-color:rgb(39,39,41)"><a href="https://www.reddit.com/r/haskell" style="text-decoration:none;color:rgb(79,188,255)" target="_blank">/r/haskell</a></span><span style="color:rgb(129,131,132);font-family:verdana,arial,helvetica,sans-serif;font-size:x-small;font-variant-ligatures:normal;background-color:rgb(39,39,41)"> </span>, I end up with a working solution like this:</div><div><br></div><div>```hs</div><div><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-wrap"><div><span style="color:rgb(204,82,75)">data</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">TypeableInstance</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75)">where</span></div><div><span style="color:rgb(126,107,95)">  -- data TypeableInstance :: forall k. k -> Type where</span></div><div><span style="color:rgb(212,191,160)">  </span><span style="color:rgb(204,161,67)">TypeableInstance</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">Typeable</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">=></span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">TypeableInstance</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span></div><br><div><span style="color:rgb(102,168,157)">typeableInstance</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-style:italic">forall</span><span style="color:rgb(150,185,70)"> </span>(<span style="color:rgb(130,174,216)">k</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">Type</span>)<span style="color:rgb(150,185,70)"> </span>(<span style="color:rgb(130,174,216)">a</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(130,174,216)">k</span>)<span style="color:rgb(204,82,75);font-weight:bold">.</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">TypeRep</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">TypeableInstance</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(130,174,216)">a</span></div><div><span style="color:rgb(212,191,160)">typeableInstance typeRep' </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> withTypeable typeRep' </span><span style="color:rgb(204,161,67)">TypeableInstance</span></div><br><div><span style="color:rgb(204,82,75)">pattern</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">TypeRep</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-style:italic">forall</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">k</span><span style="color:rgb(212,191,160)"> </span>(<span style="color:rgb(130,174,216)">a</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">k</span>)<span style="color:rgb(204,82,75);font-weight:bold">.</span><span style="color:rgb(212,191,160)"> </span>()<span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">=></span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">Typeable</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">=></span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">TypeRep</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span></div><div><span style="color:rgb(204,82,75)">pattern</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">TypeRep</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold"><-</span></div><div><span style="color:rgb(212,191,160)">  </span>(<span style="color:rgb(212,191,160)">typeableInstance </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">TypeableInstance</span>)</div><div><span style="color:rgb(212,191,160)">  </span><span style="color:rgb(204,82,75)">where</span></div><div><span style="color:rgb(212,191,160)">    </span><span style="color:rgb(204,161,67)">TypeRep</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> typeRep</span></div><br><div><span style="color:rgb(102,168,157)">holdEvent</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">Dynamic</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">Dynamic</span></div><div><span style="color:rgb(212,191,160)">holdEvent </span><span style="color:rgb(204,82,75);font-weight:bold">!</span><span style="color:rgb(212,191,160)">devs </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75)">case</span><span style="color:rgb(212,191,160)"> devs </span><span style="color:rgb(204,82,75)">of</span></div><div><span style="color:rgb(212,191,160)">  </span><span style="color:rgb(204,161,67)">Dynamic</span><span style="color:rgb(212,191,160)"> </span>(<span style="color:rgb(204,161,67)">App</span><span style="color:rgb(212,191,160)"> eventSink </span><span style="color:rgb(204,161,67)">TypeRep</span>)<span style="color:rgb(212,191,160)"> evs' </span><span style="color:rgb(204,82,75);font-weight:bold">-></span></div><div><span style="color:rgb(212,191,160)">    </span><span style="color:rgb(204,82,75)">case</span><span style="color:rgb(212,191,160)"> eqTypeRep </span>(<span style="color:rgb(212,191,160)">typeRep </span><span style="color:rgb(179,221,245)">@</span><span style="color:rgb(107,149,197)">EventSink</span>)<span style="color:rgb(212,191,160)"> eventSink </span><span style="color:rgb(204,82,75)">of</span></div><div><span style="color:rgb(212,191,160)">      </span><span style="color:rgb(204,161,67)">Just</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">HRefl</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">Dynamic</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">TypeRep</span><span style="color:rgb(212,191,160)"> </span>(<span style="color:rgb(212,191,160)">hcHoldEvent evs'</span>)</div><div><span style="color:rgb(212,191,160)">      </span><span style="color:rgb(204,161,67)">Nothing</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(212,191,160)"> error </span><span style="color:rgb(151,162,167)">"not an EventSink"</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(126,107,95)">-- to be handled properly</span></div><div><span style="color:rgb(212,191,160)">  _ </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(212,191,160)"> error </span><span style="color:rgb(151,162,167)">"even not a poly-type"</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(126,107,95)">-- to be handled properly</span></div><div><span style="color:rgb(212,191,160)">  </span><span style="color:rgb(204,82,75)">where</span></div><div><span style="color:rgb(150,185,70)">    </span><span style="color:rgb(102,168,157)">hcHoldEvent</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-style:italic">forall</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(204,82,75);font-weight:bold">.</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">EventSink</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">IO</span><span style="color:rgb(150,185,70)"> </span>(<span style="color:rgb(107,149,197)">TimeSeries</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(130,174,216)">a</span>)</div><div><span style="color:rgb(212,191,160)">    hcHoldEvent </span><span style="color:rgb(204,82,75);font-weight:bold">!</span><span style="color:rgb(212,191,160)">evs </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75)">do</span></div><div><span style="color:rgb(212,191,160)">      </span><span style="color:rgb(204,82,75);font-weight:bold">!</span><span style="color:rgb(212,191,160)">holder </span><span style="color:rgb(204,82,75);font-weight:bold"><-</span><span style="color:rgb(212,191,160)"> newIORef </span><span style="color:rgb(204,161,67)">Nothing</span></div><div><span style="color:rgb(212,191,160)">      listenEvents evs </span><span style="color:rgb(163,211,73)">$</span><span style="color:rgb(212,191,160)"> writeIORef holder </span><span style="color:rgb(163,211,73)">.</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">Just</span></div><div><span style="color:rgb(212,191,160)">      return </span><span style="color:rgb(163,211,73)">$</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">TimeSeries</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(163,211,73)">$</span><span style="color:rgb(212,191,160)"> readIORef holder</span></div><br><div><span style="color:rgb(204,82,75)">data</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">EventSink</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">EventSink</span></div><div><span style="color:rgb(212,191,160)">  </span><span style="color:rgb(204,161,67)">{</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">listenEvents</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(212,191,160)"> </span>(<span style="color:rgb(130,174,216)">a</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">IO</span><span style="color:rgb(212,191,160)"> </span>())<span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">IO</span><span style="color:rgb(212,191,160)"> </span>(),</div><div><span style="color:rgb(212,191,160)">    </span><span style="color:rgb(204,161,67)">closeStream</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">IO</span><span style="color:rgb(212,191,160)"> </span>()</div><div><span style="color:rgb(212,191,160)">  </span><span style="color:rgb(204,161,67)">}</span></div><br><div><span style="color:rgb(204,82,75)">instance</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">Functor</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">EventSink</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75)">where</span></div><div><span style="color:rgb(212,191,160)">  fmap </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> undefined</span></div><br><div><span style="color:rgb(204,82,75)">newtype</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">TimeSeries</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">TimeSeries</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">{readTimeSeries</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">IO</span><span style="color:rgb(212,191,160)"> </span>(<span style="color:rgb(107,149,197)">Maybe</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span>)<span style="color:rgb(204,161,67)">}</span></div><br><div><span style="color:rgb(204,82,75)">instance</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">Functor</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">TimeSeries</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75)">where</span></div><div><span style="color:rgb(212,191,160)">  fmap </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> undefined</span></div><br></div></div><div>```</div><div><br></div><div>I'm still wrapping my head around it, for how the `pattern TypeRep` works in this case.</div><div><br></div><div>Or you think there exists a solution without using such a pattern?</div><div><br></div><div>My function (hcHoldEvent) is polymorphic so not eligible to be wrapped as a Dynamic in the first place, or there also some way to specialize it at runtime? That'll be another interesting tool.</div><div><br></div><div>Thanks with regards,</div><div>Compl<br><div><br><blockquote type="cite"><div>On 2021-04-12, at 22:50, Erik Hesselink <<a href="mailto:hesselink@gmail.com" target="_blank">hesselink@gmail.com</a>> wrote:</div><br><div><div dir="ltr"><div>Your function is not `forall a. a -> f a`, as in your initial example, but requires its argument to be an `EventSink`. The value you unwrap from the `Dynamic` is any existential type, not necessarily an `EventSink`. You'll have to compare the TypeReps (with something like `eqTypeRep`[1], or wrap your function in a `Dynamic` and use `dynApply` [2], which does the comparison for you.<br></div><div><br></div><div>Cheers,</div><div><br></div><div>Erik</div><div><br></div><div>[1] <a href="https://hackage.haskell.org/package/base-4.15.0.0/docs/Type-Reflection.html#v:eqTypeRep" target="_blank">https://hackage.haskell.org/package/base-4.15.0.0/docs/Type-Reflection.html#v:eqTypeRep</a></div><div>[2] <a href="https://hackage.haskell.org/package/base-4.15.0.0/docs/Data-Dynamic.html#v:dynApply" target="_blank">https://hackage.haskell.org/package/base-4.15.0.0/docs/Data-Dynamic.html#v:dynApply</a></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Mon, 12 Apr 2021 at 16:15, YueCompl via ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div>Thanks to Vlad and Jaro, your solution of `apD` compiles, I think it should work.</div><div><br></div><div>But unfortunately my real case is a little different / more complex, a MWE appears like this:</div><div><br></div><div>```hs</div><div><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-wrap"><div><span style="color:rgb(102,168,157)">holdEvent</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">Dynamic</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">Dynamic</span></div><div><span style="color:rgb(212,191,160)">holdEvent </span>(<span style="color:rgb(204,161,67)">Dynamic</span><span style="color:rgb(212,191,160)"> t evs'</span>)<span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">=</span></div><div><span style="color:rgb(212,191,160)">  withTypeable t </span><span style="color:rgb(163,211,73)">$</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">Dynamic</span><span style="color:rgb(212,191,160)"> typeRep </span>(<span style="color:rgb(212,191,160)">hcHoldEvent evs'</span>)</div><div><span style="color:rgb(212,191,160)">  </span><span style="color:rgb(204,82,75)">where</span></div><div><span style="color:rgb(150,185,70)">    </span><span style="color:rgb(102,168,157)">hcHoldEvent</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-style:italic">forall</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(204,82,75);font-weight:bold">.</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">EventSink</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(107,149,197)">IO</span><span style="color:rgb(150,185,70)"> </span>(<span style="color:rgb(107,149,197)">TimeSeries</span><span style="color:rgb(150,185,70)"> </span><span style="color:rgb(130,174,216)">a</span>)</div><div><span style="color:rgb(212,191,160)">    hcHoldEvent </span><span style="color:rgb(204,82,75);font-weight:bold">!</span><span style="color:rgb(212,191,160)">evs </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75)">do</span></div><div><span style="color:rgb(212,191,160)">      </span><span style="color:rgb(204,82,75);font-weight:bold">!</span><span style="color:rgb(212,191,160)">holder </span><span style="color:rgb(204,82,75);font-weight:bold"><-</span><span style="color:rgb(212,191,160)"> newIORef </span><span style="color:rgb(204,161,67)">Nothing</span></div><div><span style="color:rgb(212,191,160)">      listenEvents evs </span><span style="color:rgb(163,211,73)">$</span><span style="color:rgb(212,191,160)"> writeIORef holder </span><span style="color:rgb(163,211,73)">.</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">Just</span></div><div><span style="color:rgb(212,191,160)">      return </span><span style="color:rgb(163,211,73)">$</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">TimeSeries</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(163,211,73)">$</span><span style="color:rgb(212,191,160)"> readIORef holder</span></div><br><div><span style="color:rgb(204,82,75)">data</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">EventSink</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">EventSink</span></div><div><span style="color:rgb(212,191,160)">  </span><span style="color:rgb(204,161,67)">{</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">listenEvents</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(212,191,160)"> </span>(<span style="color:rgb(130,174,216)">a</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">IO</span><span style="color:rgb(212,191,160)"> </span>())<span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">-></span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">IO</span><span style="color:rgb(212,191,160)"> </span>(),</div><div><span style="color:rgb(212,191,160)">    </span><span style="color:rgb(204,161,67)">closeStream</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">IO</span><span style="color:rgb(212,191,160)"> </span>()</div><div><span style="color:rgb(212,191,160)">  </span><span style="color:rgb(204,161,67)">}</span></div><br><div><span style="color:rgb(204,82,75)">instance</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">Functor</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">EventSink</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75)">where</span></div><div><span style="color:rgb(212,191,160)">  fmap </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> undefined</span></div><br><div><span style="color:rgb(204,82,75)">newtype</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">TimeSeries</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">TimeSeries</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,161,67)">{readTimeSeries</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75);font-weight:bold">::</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">IO</span><span style="color:rgb(212,191,160)"> </span>(<span style="color:rgb(107,149,197)">Maybe</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(130,174,216)">a</span>)<span style="color:rgb(204,161,67)">}</span></div><br><div><span style="color:rgb(204,82,75)">instance</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">Functor</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(107,149,197)">TimeSeries</span><span style="color:rgb(212,191,160)"> </span><span style="color:rgb(204,82,75)">where</span></div><div><span style="color:rgb(212,191,160)">  fmap </span><span style="color:rgb(204,82,75);font-weight:bold">=</span><span style="color:rgb(212,191,160)"> undefined</span></div><br></div></div><div>```</div><div><br></div><div>Now I'm clueless how to use the `withTypeable` trick to apply my polymorphic `hcHoldEvent` to `Dynamic`, naively written as in above, the error is:</div><div><br></div><div>```log</div><div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(152,244,245);background-color:rgb(22,27,24)"><span style="font-variant-ligatures:no-common-ligatures"><b>src/PoC/DynPoly.hs:20:49: </b></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(252,53,34)"><b>error:</b></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)"><span style="font-variant-ligatures:no-common-ligatures">    • Couldn't match expected type ‘EventSink a0’ with actual type ‘a’</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)"><span style="font-variant-ligatures:no-common-ligatures">      ‘a’ is a rigid type variable bound by</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)"><span style="font-variant-ligatures:no-common-ligatures">        a pattern with constructor:</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)"><span style="font-variant-ligatures:no-common-ligatures">          Dynamic :: forall a.</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)"><span style="font-variant-ligatures:no-common-ligatures">                     base-4.13.0.0:Data.Typeable.Internal.TypeRep a -> a -> Dynamic,</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)"><span style="font-variant-ligatures:no-common-ligatures">        in an equation for ‘holdEvent’</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)"><span style="font-variant-ligatures:no-common-ligatures">        at src/PoC/DynPoly.hs:19:12-25</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)"><span style="font-variant-ligatures:no-common-ligatures">    • In the first argument of ‘hcHoldEvent’, namely ‘evs'’</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)"><span style="font-variant-ligatures:no-common-ligatures">      In the second argument of ‘Dynamic’, namely ‘(hcHoldEvent evs')’</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)"><span style="font-variant-ligatures:no-common-ligatures">      In the second argument of ‘($)’, namely</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)"><span style="font-variant-ligatures:no-common-ligatures">        ‘Dynamic typeRep (hcHoldEvent evs')’</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)"><span style="font-variant-ligatures:no-common-ligatures">    • Relevant bindings include</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)"><span style="font-variant-ligatures:no-common-ligatures">        evs' :: a (bound at src/PoC/DynPoly.hs:19:22)</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)"><span style="font-variant-ligatures:no-common-ligatures">        t :: base-4.13.0.0:Data.Typeable.Internal.TypeRep a</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)"><span style="font-variant-ligatures:no-common-ligatures">          (bound at src/PoC/DynPoly.hs:19:20)</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(207,125,255);background-color:rgb(22,27,24)"><span style="font-variant-ligatures:no-common-ligatures"><b>   |</b></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)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(207,125,255)"><b>20 |</b></span><span style="font-variant-ligatures:no-common-ligatures">   withTypeable t $ Dynamic typeRep (hcHoldEvent </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(252,53,34)"><b>evs'</b></span><span style="font-variant-ligatures:no-common-ligatures">)</span></div><div style="margin:0px;font-stretch:normal;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(252,53,34);background-color:rgb(22,27,24)"><span style="font-variant-ligatures:no-common-ligatures;color:rgb(207,125,255)"><b>   |</b></span><span style="font-variant-ligatures:no-common-ligatures"><b>                                                 ^^^^</b></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);min-height:13px"><span style="font-variant-ligatures:no-common-ligatures"></span><br></div></div><div>```</div><div><br></div><div>Thanks with best regards,</div><div>Compl</div><div><br></div><div><br><blockquote type="cite"><div>On 2021-04-12, at 22:04, Jaro Reinders <<a href="mailto:jaro.reinders@gmail.com" target="_blank">jaro.reinders@gmail.com</a>> wrote:</div><br><div><span style="float:none;display:inline">I have no experience in this area, but this compiles:</span><br><br><span style="float:none;display:inline">```</span><br><span style="float:none;display:inline">{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}</span><br><span style="float:none;display:inline">import Type.Reflection</span><br><span style="float:none;display:inline">import Data.Dynamic</span><br><br><span style="float:none;display:inline">appD :: forall f. Typeable f => (forall a. a -> f a) -> Dynamic -> Dynamic</span><br><span style="float:none;display:inline">appD f (Dynamic rep (x :: a)) = withTypeable rep (toDyn (f x))</span><br><span style="float:none;display:inline">```</span><br><br><span style="float:none;display:inline">Cheers,</span><br><br><span style="float:none;display:inline">Jaro</span><br></div></blockquote><br><div><br><blockquote type="cite"><div>On 2021-04-12, at 21:06, Vladislav Zavialov <<a href="mailto:vladislav@serokell.io" target="_blank">vladislav@serokell.io</a>> wrote:</div><br><div><div>Would something like this work for you?<br><br>  import Type.Reflection<br>  import Data.Dynamic<br><br>  apD :: Typeable f => (forall a. a -> f a) -> Dynamic -> Dynamic<br>  apD f (Dynamic t a) = withTypeable t $ Dynamic typeRep (f a)<br><br>- Vlad<br><br><blockquote type="cite">On 12 Apr 2021, at 14:34, YueCompl via ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a>> wrote:<br><br>Dear Cafe and GHC devs,<br><br><br>There used to be a "principled way with pattern match on the constructor":<br><br>```hs<br>data Dynamic where<br> Dynamic :: Typeable a => a -> Dynamic<br><br>apD :: Typeable f => (forall a. a -> f a) -> Dynamic -> Dynamic<br>apD f (Dynamic a) = Dynamic $ f a<br>```<br>Source: <a href="https://www.reddit.com/r/haskell/comments/2kdcca/q_how_to_apply_a_polymorphic_function_to_a/" target="_blank">https://www.reddit.com/r/haskell/comments/2kdcca/q_how_to_apply_a_polymorphic_function_to_a/</a><br><br><br>But now with GHC 8.8 as in my case, `Dynamic` constructor has changed its signature to: <br><br>```hs<br>Dynamic :: forall a. TypeRep a -> a -> Dynamic<br>```<br><br>Which renders the `apD` not working anymore. <br><br><br>And it seems missing dependencies now for an older solution Edward KMETT provides:<br><br>```hs<br>apD :: forall f. Typeable1 f => (forall a. a -> f a) -> Dynamic -> Dynamic<br>apD f a = dynApp df a<br> where t = dynTypeRep a<br>       df = reify (mkFunTy t (typeOf1 (undefined :: f ()) `mkAppTy` t)) $ <br>                 \(_ :: Proxy s) -> toDyn (WithRep f :: WithRep s (() -> f ()))<br>```<br>Source: <a href="https://stackoverflow.com/questions/10889682/how-to-apply-a-polymorphic-function-to-a-dynamic-value" target="_blank">https://stackoverflow.com/questions/10889682/how-to-apply-a-polymorphic-function-to-a-dynamic-value</a><br><br><br>So, how can I do that nowadays?<br><br>Thanks,<br>Compl<br><br>_______________________________________________<br>ghc-devs mailing list<br><a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br></blockquote><br></div></div></blockquote></div><br></div></div>_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br>
</blockquote></div>
</div></blockquote></div><br></div></div>_______________________________________________<br>ghc-devs mailing list<br><a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br></div></blockquote></div><br></div></div></blockquote></div>