Created
September 26, 2014 14:57
-
-
Save raichoo/a0155f83b2b3fbdcb761 to your computer and use it in GitHub Desktop.
Testing a missing JavaScript primitive
This file contains hidden or 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 | |
%lib Node "readline" | |
data ReadLine = MkReadLine Ptr | |
readlineClose : ReadLine -> IO () | |
readlineClose (MkReadLine rl) = | |
mkForeign (FFun "%0.close()" [FPtr] FUnit) rl | |
onLine : ReadLine -> (String -> IO ()) -> IO () | |
onLine (MkReadLine rl) k = mkForeign ( | |
FFun "%0.on('line',%1)" [FPtr, FFunction FString (FAny (IO ()))] FUnit | |
) rl k | |
readline : IO ReadLine | |
readline = do | |
ptr <- mkForeign (FFun createInterface [] FPtr) | |
return $ MkReadLine ptr | |
where | |
createInterface : String | |
createInterface = | |
"readline.createInterface({" | |
++ " input: process.stdin," | |
++ " ouput: process.stdout," | |
++ " terminal: false" | |
++ "})" | |
main : IO () | |
main = do | |
rl <- readline | |
onLine rl (\f => do print $ negate (prim__strToFloat f) | |
readlineClose rl) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment