Safe Haskell | None |
---|---|
Language | Haskell98 |
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.
- data JSString
- data JSAny
- type URL = String
- alert :: MonadIO m => String -> m ()
- prompt :: MonadIO m => String -> m String
- eval :: MonadIO m => JSString -> m JSString
- writeLog :: MonadIO m => String -> m ()
- catJSStr :: JSString -> [JSString] -> JSString
- fromJSStr :: JSString -> String
- onHashChange :: MonadIO m => (String -> String -> IO ()) -> m ()
- onHashChange' :: MonadIO m => (JSString -> JSString -> IO ()) -> m ()
- setHash :: MonadIO m => String -> m ()
- getHash :: MonadIO m => m String
- setHash' :: MonadIO m => JSString -> m ()
- getHash' :: MonadIO m => m JSString
- class Random a where
- data Seed
- next :: Seed -> Seed
- mkSeed :: Int -> Seed
- newSeed :: MonadIO m => m Seed
- data Timer
- data Interval
- setTimer :: MonadEvent m => Interval -> m () -> m Timer
- stopTimer :: MonadIO m => Timer -> m ()
- class JSType a where
- toJSString :: a -> JSString
- fromJSString :: JSString -> Maybe a
- class JSNum a where
- toNumber :: a -> Double
- fromNumber :: Double -> a
- toString :: JSType a => a -> String
- fromString :: JSType a => String -> Maybe a
- convert :: (JSNum a, JSNum b) => a -> b
Basic utility functions
JSStrings are represented as normal strings server-side; should probably be changed to ByteString or Text.
Any JS value, with one layer of indirection.
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 two arguments of the callback are the new and old hash respectively.
onHashChange' :: MonadIO m => (JSString -> JSString -> IO ()) -> m () Source
JSString version of onHashChange
.
setHash' :: MonadIO m => JSString -> m () Source
Set the hash part of the current URL - JSString version.
Random number generation (deprecated; use the random
package instead)
Timers
Interval and repeat for timers.
:: 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.
Fast conversions for JS-native types
Any type which can be converted to/from a JSString
.
toJSString :: a -> JSString Source
fromJSString :: JSString -> Maybe a Source
(Almost) all numeric types can be efficiently converted to and from Double, which is the internal representation for most of them.
fromString :: JSType a => String -> Maybe a Source