Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 39 lines (32 sloc) 1.281 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
{-# LANGUAGE ForeignFunctionInterface, EmptyDataDecls #-}
module Haste (alert, prompt, eval, round_, fromInt, writeLog, JSString,
              catJSStr, toJSStr, fromJSStr,
              module Haste.Readable, module Haste.Showable,
              module Haste.Callback, module Haste.Random) where
import Haste.Prim
import Haste.Readable
import Haste.Showable
import Haste.Callback
import Haste.Random

foreign import ccall jsAlert :: JSString -> IO ()
foreign import ccall jsLog :: JSString -> IO ()
foreign import ccall jsPrompt :: JSString -> IO JSString
foreign import ccall jsEval :: JSString -> IO JSString
foreign import ccall jsCat :: Ptr [JSString] -> JSString -> JSString

-- | Javascript alert() function.
alert :: String -> IO ()
alert = jsAlert . toJSStr

-- | Javascript prompt() function.
prompt :: String -> IO String
prompt q = do
  a <- jsPrompt (toJSStr q)
  return (fromJSStr a)

-- | Javascript eval() function.
eval :: String -> IO String
eval js = jsEval (toJSStr js) >>= return . fromJSStr

-- | Use console.log to write a message.
writeLog :: String -> IO ()
writeLog = jsLog . toJSStr

-- | Concatenate a series of JSStrings using the specified separator.
catJSStr :: JSString -> [JSString] -> JSString
catJSStr sep strs = jsCat (toPtr strs) sep
Something went wrong with that request. Please try again.