Portability | portable |
---|---|

Stability | experimental |

Maintainer | golubovsky@gmail.com |

Encoding of Javascript arithmetic and mathematic operations.

- lt :: Expression a -> Expression a -> Expression Bool
- le :: Expression a -> Expression a -> Expression Bool
- gt :: Expression a -> Expression a -> Expression Bool
- ge :: Expression a -> Expression a -> Expression Bool
- eq :: Expression a -> Expression a -> Expression Bool
- ne :: Expression a -> Expression a -> Expression Bool
- (===) :: Expression a -> Expression a -> Expression Bool
- (=/=) :: Expression a -> Expression a -> Expression Bool
- land :: Expression Bool -> Expression Bool -> Expression Bool
- lor :: Expression Bool -> Expression Bool -> Expression Bool
- isNAN :: Expression Double -> JSMW e (Expression Bool)
- toString :: Expression a -> JSMW e (Expression String)
- parseInt :: Expression String -> Expression Double -> JSMW e (Expression Double)
- parseFloat :: Expression String -> JSMW e (Expression Double)

# Arithmetic operators

Instance of the `Num`

class can be defined for Javascript expressions
provided that their type annotation also belongs to the `Num`

class. Therefore
it is possible to overload the `+`

, `-`

, etc. operators so that using them
in JSMW code would result in correct Javascript code:

`number`

5 - (`number`

1 -`number`

4)

results in

`(5.0 - (1.0 - 4.0))`

.

Also, addition is defined for String expressions, so this is possible:

`alert`

(g +`string`

" Greater than 3")

Unlike the methods of the `Num`

class, comparison operators (members of the `Ord`

class) cannot be overloaded in suitable manner. For Javascript expressions,
the following infix operators are provided, with the same fixity as the corresponding
Haskell operators.

lt :: Expression a -> Expression a -> Expression BoolSource

le :: Expression a -> Expression a -> Expression BoolSource

gt :: Expression a -> Expression a -> Expression BoolSource

ge :: Expression a -> Expression a -> Expression BoolSource

eq :: Expression a -> Expression a -> Expression BoolSource

ne :: Expression a -> Expression a -> Expression BoolSource

(===) :: Expression a -> Expression a -> Expression BoolSource

(=/=) :: Expression a -> Expression a -> Expression BoolSource

# Logical operators

Similarly, logical operators for Javascript expressions are provided.

land :: Expression Bool -> Expression Bool -> Expression BoolSource

lor :: Expression Bool -> Expression Bool -> Expression BoolSource

# Tests for being a number

isNAN :: Expression Double -> JSMW e (Expression Bool)Source

Test if a given value is a number.

# Primitive conversions

toString :: Expression a -> JSMW e (Expression String)Source

Obtain a string representation of an arbitrary Javascript expression.

parseInt :: Expression String -> Expression Double -> JSMW e (Expression Double)Source

Parse an integer.

parseFloat :: Expression String -> JSMW e (Expression Double)Source

Parse a floating point number.