Created
May 13, 2014 00:59
-
-
Save paf31/4c2357f5014f2207b898 to your computer and use it in GitHub Desktop.
Existential types as a library
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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