Skip to content

Instantly share code, notes, and snippets.

@raichoo
Created September 26, 2014 14:57
Show Gist options
  • Save raichoo/a0155f83b2b3fbdcb761 to your computer and use it in GitHub Desktop.
Save raichoo/a0155f83b2b3fbdcb761 to your computer and use it in GitHub Desktop.
Testing a missing JavaScript primitive
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