<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="">Thanks Erik,<div class=""><br class=""></div><div class="">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; orphans: 2; widows: 2; background-color: rgb(39, 39, 41); text-decoration-thickness: initial;" class="">from </span><span class="sender" style="color: rgb(129, 131, 132); font-family: verdana, arial, helvetica, sans-serif; font-size: x-small; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(39, 39, 41); text-decoration-thickness: initial;"><a href="https://www.reddit.com/user/Iceland_jack" class="may-blank author id-t2_3qjdu" style="text-decoration: none; color: rgb(79, 188, 255); margin-right: 0.5em;">Iceland_jack</a><span class="userattrs"></span></span><span style="color: rgb(129, 131, 132); font-family: verdana, arial, helvetica, sans-serif; font-size: x-small; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(39, 39, 41); text-decoration-thickness: initial;" class=""> via </span><span class="subreddit" style="margin-bottom: 10px; color: rgb(129, 131, 132); font-family: verdana, arial, helvetica, sans-serif; font-size: x-small; font-variant-ligatures: normal; orphans: 2; widows: 2; background-color: rgb(39, 39, 41); text-decoration-thickness: initial;"><a href="https://www.reddit.com/r/haskell" style="text-decoration: none; color: rgb(79, 188, 255);" class="">/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; orphans: 2; widows: 2; background-color: rgb(39, 39, 41); text-decoration-thickness: initial;" class=""> </span>, I end up with a working solution like this:</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="">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: #7e6b5f;" class=""> -- data TypeableInstance :: forall k. k -> Type 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: #cc524b;font-style: italic;" class="">forall</span><span style="color: #96b946;" class=""> </span>(<span style="color: #82aed8;" class="">k</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="">Type</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: #82aed8;" class="">k</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 typeRep' </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> withTypeable typeRep' </span><span style="color: #cca143;" class="">TypeableInstance</span></div><br class=""><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></div><div class=""><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></div><div class=""><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: #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: #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="">holdEvent </span><span style="color: #cc524b;font-weight: bold;" class="">!</span><span style="color: #d4bfa0;" class="">devs </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=""> devs </span><span style="color: #cc524b;" class="">of</span></div><div class=""><span style="color: #d4bfa0;" class=""> </span><span style="color: #cca143;" class="">Dynamic</span><span style="color: #d4bfa0;" class=""> </span>(<span style="color: #cca143;" class="">App</span><span style="color: #d4bfa0;" class=""> eventSink </span><span style="color: #cca143;" class="">TypeRep</span>)<span style="color: #d4bfa0;" class=""> evs' </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=""> eqTypeRep </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=""> eventSink </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="">hcHoldEvent evs'</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="">hcHoldEvent</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=""> hcHoldEvent </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="">closeStream</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="">instance</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Functor</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">EventSink</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span></div><div class=""><span style="color: #d4bfa0;" class=""> fmap </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> undefined</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: #cc524b;" class="">instance</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">Functor</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #6b95c5;" class="">TimeSeries</span><span style="color: #d4bfa0;" class=""> </span><span style="color: #cc524b;" class="">where</span></div><div class=""><span style="color: #d4bfa0;" class=""> fmap </span><span style="color: #cc524b;font-weight: bold;" class="">=</span><span style="color: #d4bfa0;" class=""> undefined</span></div><br class=""></div></div><div class="">```</div><div class=""><br class=""></div><div class="">I'm still wrapping my head around it, for how the `pattern TypeRep` works in this case.</div><div class=""><br class=""></div><div class="">Or you think there exists a solution without using such a pattern?</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">Thanks with regards,</div><div class="">Compl<br class=""><div><br class=""><blockquote type="cite" class=""><div class="">On 2021-04-12, at 22: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="">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 class=""></div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Erik</div><div class=""><br class=""></div><div class="">[1] <a href="https://hackage.haskell.org/package/base-4.15.0.0/docs/Type-Reflection.html#v:eqTypeRep" class="">https://hackage.haskell.org/package/base-4.15.0.0/docs/Type-Reflection.html#v:eqTypeRep</a></div><div class="">[2] <a href="https://hackage.haskell.org/package/base-4.15.0.0/docs/Data-Dynamic.html#v:dynApply" class="">https://hackage.haskell.org/package/base-4.15.0.0/docs/Data-Dynamic.html#v:dynApply</a></div></div><br class=""><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" class="">ghc-devs@haskell.org</a>> wrote:<br class=""></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;" class=""><div class="">Thanks to Vlad and Jaro, your solution of `apD` compiles, I think it should work.</div><div class=""><br class=""></div><div class="">But unfortunately my real case is a little different / more complex, a MWE appears like this:</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-wrap" class=""><div class=""><span style="color:rgb(102,168,157)" class="">holdEvent</span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">::</span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(107,149,197)" class="">Dynamic</span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">-></span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(107,149,197)" class="">Dynamic</span></div><div class=""><span style="color:rgb(212,191,160)" class="">holdEvent </span>(<span style="color:rgb(204,161,67)" class="">Dynamic</span><span style="color:rgb(212,191,160)" class=""> t evs'</span>)<span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">=</span></div><div class=""><span style="color:rgb(212,191,160)" class=""> withTypeable t </span><span style="color:rgb(163,211,73)" class="">$</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,161,67)" class="">Dynamic</span><span style="color:rgb(212,191,160)" class=""> typeRep </span>(<span style="color:rgb(212,191,160)" class="">hcHoldEvent evs'</span>)</div><div class=""><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75)" class="">where</span></div><div class=""><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(102,168,157)" class="">hcHoldEvent</span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">::</span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(204,82,75);font-style:italic" class="">forall</span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(130,174,216)" class="">a</span><span style="color:rgb(204,82,75);font-weight:bold" class="">.</span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(107,149,197)" class="">EventSink</span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(130,174,216)" class="">a</span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">-></span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(107,149,197)" class="">IO</span><span style="color:rgb(150,185,70)" class=""> </span>(<span style="color:rgb(107,149,197)" class="">TimeSeries</span><span style="color:rgb(150,185,70)" class=""> </span><span style="color:rgb(130,174,216)" class="">a</span>)</div><div class=""><span style="color:rgb(212,191,160)" class=""> hcHoldEvent </span><span style="color:rgb(204,82,75);font-weight:bold" class="">!</span><span style="color:rgb(212,191,160)" class="">evs </span><span style="color:rgb(204,82,75);font-weight:bold" class="">=</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75)" class="">do</span></div><div class=""><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">!</span><span style="color:rgb(212,191,160)" class="">holder </span><span style="color:rgb(204,82,75);font-weight:bold" class=""><-</span><span style="color:rgb(212,191,160)" class=""> newIORef </span><span style="color:rgb(204,161,67)" class="">Nothing</span></div><div class=""><span style="color:rgb(212,191,160)" class=""> listenEvents evs </span><span style="color:rgb(163,211,73)" class="">$</span><span style="color:rgb(212,191,160)" class=""> writeIORef holder </span><span style="color:rgb(163,211,73)" class="">.</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,161,67)" class="">Just</span></div><div class=""><span style="color:rgb(212,191,160)" class=""> return </span><span style="color:rgb(163,211,73)" class="">$</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,161,67)" class="">TimeSeries</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(163,211,73)" class="">$</span><span style="color:rgb(212,191,160)" class=""> readIORef holder</span></div><br class=""><div class=""><span style="color:rgb(204,82,75)" class="">data</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(107,149,197)" class="">EventSink</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(130,174,216)" class="">a</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">=</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,161,67)" class="">EventSink</span></div><div class=""><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,161,67)" class="">{</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,161,67)" class="">listenEvents</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">::</span><span style="color:rgb(212,191,160)" class=""> </span>(<span style="color:rgb(130,174,216)" class="">a</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">-></span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(107,149,197)" class="">IO</span><span style="color:rgb(212,191,160)" class=""> </span>())<span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">-></span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(107,149,197)" class="">IO</span><span style="color:rgb(212,191,160)" class=""> </span>(),</div><div class=""><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,161,67)" class="">closeStream</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">::</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(107,149,197)" class="">IO</span><span style="color:rgb(212,191,160)" class=""> </span>()</div><div class=""><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,161,67)" class="">}</span></div><br class=""><div class=""><span style="color:rgb(204,82,75)" class="">instance</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(107,149,197)" class="">Functor</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(107,149,197)" class="">EventSink</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75)" class="">where</span></div><div class=""><span style="color:rgb(212,191,160)" class=""> fmap </span><span style="color:rgb(204,82,75);font-weight:bold" class="">=</span><span style="color:rgb(212,191,160)" class=""> undefined</span></div><br class=""><div class=""><span style="color:rgb(204,82,75)" class="">newtype</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(107,149,197)" class="">TimeSeries</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(130,174,216)" class="">a</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">=</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,161,67)" class="">TimeSeries</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,161,67)" class="">{readTimeSeries</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75);font-weight:bold" class="">::</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(107,149,197)" class="">IO</span><span style="color:rgb(212,191,160)" class=""> </span>(<span style="color:rgb(107,149,197)" class="">Maybe</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(130,174,216)" class="">a</span>)<span style="color:rgb(204,161,67)" class="">}</span></div><br class=""><div class=""><span style="color:rgb(204,82,75)" class="">instance</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(107,149,197)" class="">Functor</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(107,149,197)" class="">TimeSeries</span><span style="color:rgb(212,191,160)" class=""> </span><span style="color:rgb(204,82,75)" class="">where</span></div><div class=""><span style="color:rgb(212,191,160)" class=""> fmap </span><span style="color:rgb(204,82,75);font-weight:bold" class="">=</span><span style="color:rgb(212,191,160)" class=""> undefined</span></div><br class=""></div></div><div class="">```</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">```log</div><div class=""><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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><b class="">src/PoC/DynPoly.hs:20:49: </b></span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(252,53,34)" class=""><b class="">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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> • 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> ‘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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> • 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> ‘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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> • 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> 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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""> (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)" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""><b class=""> |</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)" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(207,125,255)" class=""><b class="">20 |</b></span><span style="font-variant-ligatures:no-common-ligatures" class=""> withTypeable t $ Dynamic typeRep (hcHoldEvent </span><span style="font-variant-ligatures:no-common-ligatures;color:rgb(252,53,34)" class=""><b class="">evs'</b></span><span style="font-variant-ligatures:no-common-ligatures" class="">)</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)" class=""><span style="font-variant-ligatures:no-common-ligatures;color:rgb(207,125,255)" class=""><b class=""> |</b></span><span style="font-variant-ligatures:no-common-ligatures" class=""><b class=""> ^^^^</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" class=""><span style="font-variant-ligatures:no-common-ligatures" class=""></span><br class=""></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><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 2021-04-12, at 22:04, Jaro Reinders <<a href="mailto:jaro.reinders@gmail.com" target="_blank" class="">jaro.reinders@gmail.com</a>> wrote:</div><br class=""><div class=""><span style="float:none;display:inline" class="">I have no experience in this area, but this compiles:</span><br class=""><br class=""><span style="float:none;display:inline" class="">```</span><br class=""><span style="float:none;display:inline" class="">{-# LANGUAGE RankNTypes, ScopedTypeVariables #-}</span><br class=""><span style="float:none;display:inline" class="">import Type.Reflection</span><br class=""><span style="float:none;display:inline" class="">import Data.Dynamic</span><br class=""><br class=""><span style="float:none;display:inline" class="">appD :: forall f. Typeable f => (forall a. a -> f a) -> Dynamic -> Dynamic</span><br class=""><span style="float:none;display:inline" class="">appD f (Dynamic rep (x :: a)) = withTypeable rep (toDyn (f x))</span><br class=""><span style="float:none;display:inline" class="">```</span><br class=""><br class=""><span style="float:none;display:inline" class="">Cheers,</span><br class=""><br class=""><span style="float:none;display:inline" class="">Jaro</span><br class=""></div></blockquote><br class=""><div class=""><br class=""><blockquote type="cite" class=""><div class="">On 2021-04-12, at 21:06, Vladislav Zavialov <<a href="mailto:vladislav@serokell.io" target="_blank" class="">vladislav@serokell.io</a>> wrote:</div><br class=""><div class=""><div class="">Would something like this work for you?<br class=""><br class=""> import Type.Reflection<br class=""> import Data.Dynamic<br class=""><br class=""> apD :: Typeable f => (forall a. a -> f a) -> Dynamic -> Dynamic<br class=""> apD f (Dynamic t a) = withTypeable t $ Dynamic typeRep (f a)<br class=""><br class="">- Vlad<br class=""><br class=""><blockquote type="cite" class="">On 12 Apr 2021, at 14:34, YueCompl via ghc-devs <<a href="mailto:ghc-devs@haskell.org" target="_blank" class="">ghc-devs@haskell.org</a>> wrote:<br class=""><br class="">Dear Cafe and GHC devs,<br class=""><br class=""><br class="">There used to be a "principled way with pattern match on the constructor":<br class=""><br class="">```hs<br class="">data Dynamic where<br class=""> Dynamic :: Typeable a => a -> Dynamic<br class=""><br class="">apD :: Typeable f => (forall a. a -> f a) -> Dynamic -> Dynamic<br class="">apD f (Dynamic a) = Dynamic $ f a<br class="">```<br class="">Source: <a href="https://www.reddit.com/r/haskell/comments/2kdcca/q_how_to_apply_a_polymorphic_function_to_a/" target="_blank" class="">https://www.reddit.com/r/haskell/comments/2kdcca/q_how_to_apply_a_polymorphic_function_to_a/</a><br class=""><br class=""><br class="">But now with GHC 8.8 as in my case, `Dynamic` constructor has changed its signature to: <br class=""><br class="">```hs<br class="">Dynamic :: forall a. TypeRep a -> a -> Dynamic<br class="">```<br class=""><br class="">Which renders the `apD` not working anymore. <br class=""><br class=""><br class="">And it seems missing dependencies now for an older solution Edward KMETT provides:<br class=""><br class="">```hs<br class="">apD :: forall f. Typeable1 f => (forall a. a -> f a) -> Dynamic -> Dynamic<br class="">apD f a = dynApp df a<br class=""> where t = dynTypeRep a<br class=""> df = reify (mkFunTy t (typeOf1 (undefined :: f ()) `mkAppTy` t)) $ <br class=""> \(_ :: Proxy s) -> toDyn (WithRep f :: WithRep s (() -> f ()))<br class="">```<br class="">Source: <a href="https://stackoverflow.com/questions/10889682/how-to-apply-a-polymorphic-function-to-a-dynamic-value" target="_blank" class="">https://stackoverflow.com/questions/10889682/how-to-apply-a-polymorphic-function-to-a-dynamic-value</a><br class=""><br class=""><br class="">So, how can I do that nowadays?<br class=""><br class="">Thanks,<br class="">Compl<br class=""><br class="">_______________________________________________<br class="">ghc-devs mailing list<br class=""><a href="mailto:ghc-devs@haskell.org" target="_blank" class="">ghc-devs@haskell.org</a><br class=""><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" target="_blank" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br class=""></blockquote><br class=""></div></div></blockquote></div><br class=""></div></div>_______________________________________________<br class="">
ghc-devs mailing list<br class="">
<a href="mailto:ghc-devs@haskell.org" target="_blank" class="">ghc-devs@haskell.org</a><br class="">
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs" rel="noreferrer" target="_blank" class="">http://mail.haskell.org/cgi-bin/mailman/listinfo/ghc-devs</a><br class="">
</blockquote></div>
</div></blockquote></div><br class=""></div></body></html>