Idris JavaScript FFI
IdrisからJavaScriptのAPIを叩いてみる。
module Main getElementById : String -> IO Ptr getElementById s = mkForeign (FFun "document.getElementById(%0)" [FString] FPtr) s setInnerHTML : String -> Ptr -> IO String setInnerHTML s e = mkForeign (FFun "%1.innerHTML = %0" [FString, FPtr] FString) s e main : IO () main = do elm <- getElementById "hello" setInnerHTML "Hello, world!" elm return ()
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>hello</title> </head> <body> <div id="hello">#hello</div> <script src="hello.js"></script> </body> </html>
idris --codegen javascript hello.idr -o hello.js open index.html
成果物: http://mandel59.github.io/idris_hello_js/
github: mandel59/idris_hello_js · GitHub