Safe Haskell | None |
---|
Create functions on the fly from JS strings. Slower but more flexible alternative to the standard FFI.
Documentation
Class for marshallable types. Pack takes an opaque JS value and turns it into the type's proper Haste representation, and unpack is its inverse. The default instances make an effort to prevent wrongly typed values through, but you could probably break them with enough creativity.
Marshal Bool | |
Marshal Double | |
Marshal Float | |
Marshal Int | |
Marshal Int8 | |
Marshal Int16 | |
Marshal Int32 | |
Marshal Word | |
Marshal Word8 | |
Marshal Word16 | |
Marshal Word32 | |
Marshal String | |
Marshal () | |
Marshal JSString | |
Marshal Unpacked | |
Marshal Blob | |
Marshal BlobData | |
Marshal Elem | |
Marshal WebSocket | |
Marshal a => Marshal [a] | Lists are marshalled into arrays. |
Marshal a => Marshal (Maybe a) | Maybe is simply a nullable type. Nothing is equivalent to null, and any non-null value is equivalent to x in Just x. |
Marshal (Opaque a) |
Opaque type representing a raw, unpacked JS value. The constructors have no meaning, but are only there to make sure GHC doesn't optimize the low level hackery in this module into oblivion.
The Opaque type is inhabited by values that can be passed to Javascript using their raw Haskell representation. Opaque values are completely useless to Javascript code, and should not be inspected. This is useful for, for instance, storing data in some Javascript-native data structure for later retrieval.
ffi :: FFI a => JSString -> aSource
Creates a function based on the given string of Javascript code. If this code is not well typed or is otherwise incorrect, your program may crash or misbehave in mystifying ways. Haste makes a best-effort try to save you from poorly typed JS here, but there are no guarantees.
For instance, the following WILL cause crazy behavior due to wrong types: ffi (function(x) {return x+1;}) :: Int -> Int -> IO Int
In other words, this function is completely unsafe - use with caution.
ALWAYS use type signatures for functions defined using this function, as the argument marshalling is decided by the type signature.
export :: FFI a => JSString -> a -> IO ()Source
Export a symbol. That symbol may then be accessed from Javascript through Haste.name() as a normal function. Remember, however, that if you are using --with-js to include your JS, in conjunction with --opt-google-closure or any option that implies it, you will instead need to access your exports through Haste['name'](), or Closure will mangle your function names.
fromOpaque :: Opaque a -> aSource