haste-compiler-0.4.1: Haskell To ECMAScript compiler

Safe HaskellNone

Haste.Foreign

Description

Create functions on the fly from JS strings. Slower but more flexible alternative to the standard FFI.

Synopsis

Documentation

class FFI a Source

Instances

Pack a => FFI (IO a) 
(Unpack a, FFI b) => FFI (a -> b) 

class Pack a whereSource

Methods

pack :: Unpacked -> aSource

Instances

Pack Bool 
Pack Double 
Pack Float 
Pack Int 
Pack Int8 
Pack Int16 
Pack Int32 
Pack Word 
Pack Word8 
Pack Word16 
Pack Word32 
Pack String 
Pack () 
Pack JSString 
Pack JSAny 
Pack Unpacked 
Pack Blob 
Pack BlobData 
Pack Elem 
Pack WebSocket 
Pack a => Pack [a]

Lists are marshalled into arrays.

Pack a => Pack (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.

Pack (Opaque a) 
(Pack a, Pack b) => Pack (a, b)

Tuples are marshalled into arrays.

(Pack a, Pack b, Pack c) => Pack (a, b, c) 
(Pack a, Pack b, Pack c, Pack d) => Pack (a, b, c, d) 
(Pack a, Pack b, Pack c, Pack d, Pack e) => Pack (a, b, c, d, e) 
(Pack a, Pack b, Pack c, Pack d, Pack e, Pack f) => Pack (a, b, c, d, e, f) 
(Pack a, Pack b, Pack c, Pack d, Pack e, Pack f, Pack g) => Pack (a, b, c, d, e, f, g) 
(Pack a, Pack b, Pack c, Pack d, Pack e, Pack f, Pack g, Pack h) => Pack (a, b, c, d, e, f, g, h) 
(Pack a, Pack b, Pack c, Pack d, Pack e, Pack f, Pack g, Pack h, Pack i) => Pack (a, b, c, d, e, f, g, h, i) 
(Pack a, Pack b, Pack c, Pack d, Pack e, Pack f, Pack g, Pack h, Pack i, Pack j) => Pack (a, b, c, d, e, f, g, h, i, j) 

class Unpack a whereSource

Methods

unpack :: a -> UnpackedSource

Instances

Unpack Bool 
Unpack Double 
Unpack Float 
Unpack Int 
Unpack Int8 
Unpack Int16 
Unpack Int32 
Unpack Word 
Unpack Word8 
Unpack Word16 
Unpack Word32 
Unpack String 
Unpack () 
Unpack JSString 
Unpack JSAny 
Unpack Unpacked 
Unpack Blob 
Unpack BlobData 
Unpack Elem 
Unpack WebSocket 
Unpack a => Unpack [a]

Lists are marshalled into arrays.

Unpack a => Unpack (IO a) 
Unpack a => Unpack (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.

Unpack (Opaque a) 
IOFun (a -> b) => Unpack (a -> b) 
(Unpack a, Unpack b) => Unpack (a, b)

Tuples are marshalled into arrays.

(Unpack a, Unpack b, Unpack c) => Unpack (a, b, c) 
(Unpack a, Unpack b, Unpack c, Unpack d) => Unpack (a, b, c, d) 
(Unpack a, Unpack b, Unpack c, Unpack d, Unpack e) => Unpack (a, b, c, d, e) 
(Unpack a, Unpack b, Unpack c, Unpack d, Unpack e, Unpack f) => Unpack (a, b, c, d, e, f) 
(Unpack a, Unpack b, Unpack c, Unpack d, Unpack e, Unpack f, Unpack g) => Unpack (a, b, c, d, e, f, g) 
(Unpack a, Unpack b, Unpack c, Unpack d, Unpack e, Unpack f, Unpack g, Unpack h) => Unpack (a, b, c, d, e, f, g, h) 
(Unpack a, Unpack b, Unpack c, Unpack d, Unpack e, Unpack f, Unpack g, Unpack h, Unpack i) => Unpack (a, b, c, d, e, f, g, h, i) 
(Unpack a, Unpack b, Unpack c, Unpack d, Unpack e, Unpack f, Unpack g, Unpack h, Unpack i, Unpack j) => Unpack (a, b, c, d, e, f, g, h, i, j) 

class (Pack a, Unpack a) => Marshal a Source

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.

Instances

(Pack a, Unpack a) => Marshal a 

data Unpacked Source

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.

data Opaque a Source

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.

Instances

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 :: Unpack 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.