jsmw-0.1: Javascript Monadic Writer base package.





Encoding of Javascript arithmetic and mathematic operations.


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.

Logical operators

Similarly, logical operators for Javascript expressions are provided.

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.

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

Parse a floating point number.