Skip to content

Instantly share code, notes, and snippets.

@chrisdone-artificial
Created October 2, 2025 11:21
Show Gist options
  • Save chrisdone-artificial/820ef652c6860fb5ffb8031759ebe3e9 to your computer and use it in GitHub Desktop.
Save chrisdone-artificial/820ef652c6860fb5ffb8031759ebe3e9 to your computer and use it in GitHub Desktop.
sweet.hs
newtype L c t = L (forall e. Dict (c (t e)))
withL :: forall c t r. L c t -> (forall e. Dict (c (t e)) -> r) -> r
withL (L dict) r = r dict
functorEitherL :: L Functor Either
functorEitherL = L Dict
someFuntorEitherL :: Dynamic
someFuntorEitherL = toDyn functorEitherL
getItBack :: Dynamic -> TypeRep (L c t) -> Maybe (L c t)
getItBack (Dynamic rep a) l_t =
case rep of
_ | Just Type.HRefl <- Type.eqTypeRep l_t rep
-> Just a
_ -> Nothing
applyClass :: Dynamic -> TypeRep (L c t) ->
(forall e. Dict (c (t e)) -> r) -> Maybe r
applyClass dyn l_t f = do
l <- getItBack dyn l_t
pure $ withL l f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment