Skip to content

Instantly share code, notes, and snippets.

@paf31
Created May 13, 2014 00:59
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 paf31/4c2357f5014f2207b898 to your computer and use it in GitHub Desktop.
Save paf31/4c2357f5014f2207b898 to your computer and use it in GitHub Desktop.
Existential types as a library
module Main where
foreign import data Exists :: (* -> *) -> *
foreign import mkExists
"function mkExists(fa) {\
\ return fa;\
\}" :: forall f a. f a -> Exists f
foreign import runExists
"function runExists(f) {\
\ return function(fa) {\
\ return f(fa);\
\ };\
\}" :: forall f r. (forall a. f a -> r) -> Exists f -> r
data Example a = Example a (a -> String)
runExample :: Exists Example -> String
runExample = runExists (\(Example a f) -> f a)
test = runExample (mkExists (Example 123 show))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment