Skip to content

Instantly share code, notes, and snippets.

@jmatsushita
Last active October 14, 2021 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jmatsushita/11a6aeac997f56e2d3572499bb2f9707 to your computer and use it in GitHub Desktop.
Save jmatsushita/11a6aeac997f56e2d3572499bb2f9707 to your computer and use it in GitHub Desktop.
Existential types with constraints
module Main where
import Prelude
newtype AnyShow = AnyShow (forall r. (forall a. Show a => a -> r) -> r)
mkAnyShow :: forall a. Show a => a -> AnyShow
mkAnyShow a = AnyShow (_ $ a)
elimAnyShow :: forall r. (forall a. Show a => a -> r) -> AnyShow -> r
elimAnyShow f (AnyShow a) = f a
instance Show AnyShow where
show (AnyShow a) = a show
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment