Permalink
Browse files

Test code

  • Loading branch information...
1 parent 1e0109c commit 0918bbc71f36698ec7fbcf5d91db113d926972c5 @norm2782 norm2782 committed Nov 4, 2011
@@ -0,0 +1,20 @@
+import Language.UHC.JScript.ECMA.String
+import Language.UHC.JScript.Assorted
+import Language.UHC.JScript.Primitives
+import Language.UHC.JScript.JQuery.JQuery
+import UHC.Ptr
+
+
+foreign import jscript "getJSFun(%1)"
+ getJSFun :: Int -> FunPtr (Int -> Int)
+
+foreign import jscript "dynamic"
+ mkDyn :: FunPtr (Int -> Int) -> (Int -> Int)
+
+main :: IO ()
+main = do
+ putStrLn "import_dynamic"
+ let jfn = getJSFun 2
+ let hfn = mkDyn jfn
+ print $ hfn 3
+
@@ -1,38 +0,0 @@
-import Language.UHC.JScript.ECMA.String
-import Language.UHC.JScript.Assorted
-import Language.UHC.JScript.Primitives
-import Language.UHC.JScript.JQuery.JQuery
-import UHC.Ptr
-
-
-foreign import jscript "some_function(%*)"
- someFun :: Int -> Int -> FunPtr (Int -> Int -> IO ()) -> IO ()
-
-foreign import jscript "wrapper"
- wrap :: (Int -> Int -> IO ()) -> IO (FunPtr (Int -> Int -> IO ()))
-
-myCB :: Int -> Int -> IO ()
-myCB _ = alert . show
-
-main :: IO ()
-main = do
- putStrLn "data_export_wrapper"
- sf <- wrap myCB
- someFun 2 3 sf
-
-{-
-
-We now require all functions in an exported constructor to be wrapped in an
-IO JSFunPtr construction. To enforce this, we need to modify the type-checker.
-We then also need to implement wrapper support in the FFI and do lambda lifting
-for lambda functions based on the wrappers
-
-
-Why do we want to wrap functions in IO JSFunPtr?
-Because otherwise a plain JS function would get a Haskell representation of a
-function, i.e., a: new _A_(new _F_(...)) etc. Regular JS functions do not know
-how to deal with these, so we need to wrap them in a regular JS function, which
-takes as many arguments as the Haskell function. The Haskell function is then
-applied to the arguments and the result is returned. This also explains the
-name wrapper....
--}
@@ -1,5 +1,5 @@
-function some_function(arg1, arg2, callback) {
- var num = Math.ceil(arg1 + arg2);
- var res = callback(num);
- return res;
-}
+function getJSFun(x) {
+ return function(y) {
+ return x + y;
+ };
+};

0 comments on commit 0918bbc

Please sign in to comment.