haste-compiler-0.5.5.0: Haskell To ECMAScript compiler

Safe HaskellNone
LanguageHaskell98

Haste

Contents

Description

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.

Synopsis

Basic utility functions

data JSString

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

data JSAny

Any JS value, with one layer of indirection.

type URL = String

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

Javascript alert() function.

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

Javascript prompt() function.

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

Javascript eval() function.

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

Use console.log to write a message.

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

Concatenate a series of JSStrings using the specified separator.

URL hash handling

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

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 ()

JSString version of onHashChange.

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

Set the hash part of the current URL.

getHash :: MonadIO m => m String

Read the hash part of the currunt URL.

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

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

getHash' :: MonadIO m => m JSString

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

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

class Random a where

Minimal complete definition

randomR

Methods

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

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

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

data Seed

next :: Seed -> Seed

Generate the next seed in the sequence.

mkSeed :: Int -> Seed

Create a new seed from an integer.

newSeed :: MonadIO m => m Seed

Generate a new seed using JavaScript's PRNG.

Timers

data Timer

Timer handle.

data Interval

Interval and repeat for timers.

Constructors

Once !Int

Fire once, in n milliseconds.

Repeat !Int

Fire every n milliseconds.

setTimer

Arguments

:: 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 ()

Stop a timer.

Fast conversions for JS-native types

class JSNum a where

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

Methods

toNumber :: a -> Double

fromNumber :: Double -> a

toString :: JSType a => a -> String

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