haste-compiler- Haskell To ECMAScript compiler

Safe HaskellNone




Haste's companion to the Prelude.

Note that this module should *not* be imported together with Haste.App, which provides the same functionality but slightly modified for automatic program slicing.


Basic utility functions

data JSString Source

JSStrings are represented as normal strings server-side; should probably be changed to ByteString or Text.

data JSAny Source

Any JS value, with one layer of indirection.

alert :: MonadIO m => String -> m () Source

Javascript alert() function.

prompt :: MonadIO m => String -> m String Source

Javascript prompt() function.

eval :: MonadIO m => JSString -> m JSString Source

Javascript eval() function.

writeLog :: MonadIO m => String -> m () Source

Use console.log to write a message.

catJSStr :: JSString -> [JSString] -> JSString Source

Concatenate a series of JSStrings using the specified separator.

URL hash handling

onHashChange :: MonadIO m => (String -> String -> IO ()) -> m () Source

Register a callback to be run whenever the URL hash changes. The first and second argument of the callback are the old and new and hash respectively.

onHashChange' :: MonadIO m => (JSString -> JSString -> IO ()) -> m () Source

JSString version of onHashChange.

setHash :: MonadIO m => String -> m () Source

Set the hash part of the current URL.

getHash :: MonadIO m => m String Source

Read the hash part of the currunt URL.

setHash' :: MonadIO m => JSString -> m () Source

Set the hash part of the current URL - JSString version.

getHash' :: MonadIO m => m JSString Source

Read the hash part of the currunt URL - JSString version.

Random number generation (deprecated; use the random package instead)

class Random a where Source

Minimal complete definition



randomR :: (a, a) -> Seed -> (a, Seed) Source

Generate a pseudo random number between a lower (inclusive) and higher (exclusive) bound.

randomRs :: (a, a) -> Seed -> [a] Source

next :: Seed -> Seed Source

Generate the next seed in the sequence.

mkSeed :: Int -> Seed Source

Create a new seed from an integer.

newSeed :: MonadIO m => m Seed Source

Generate a new seed using JavaScript's PRNG.


data Timer Source

Timer handle.

data Interval Source

Interval and repeat for timers.


Once !Int

Fire once, in n milliseconds.

Repeat !Int

Fire every n milliseconds.

setTimer Source


:: MonadEvent m 
=> Interval

Milliseconds until timer fires.

-> m ()

Function to call when timer fires.

-> m Timer

Timer handle for interacting with the timer.

Set a timer.

stopTimer :: MonadIO m => Timer -> m () Source

Stop a timer.

Fast conversions for JS-native types

class JSNum a where Source

(Almost) all numeric types can be efficiently converted to and from Double, which is the internal representation for most of them.

convert :: (JSNum a, JSNum b) => a -> b Source