git.iko.soy/rowtype-yoga/purescript-native
on 8030607 help sign in
31 lines 959 B history raw
1Foreign Function Interface
2==========================
4Importing Values
5----------------
7The `foreign import` keyword declares a value which is defined in Javascript, and its type::
9 foreign import pow :: Number -> Number -> Number
11Inline Javascript
12-----------------
14A foreign import declaration may optionally contain its definition in Javascript as a string literal. If this is provided, the string will be inserted directly into the generated Javascript before the current module definition::
16 foreign import pow "function pow(n) {\
17 \ return function(p) {\
18 \ return Math.pow(n, p);\
19 \ };\
20 \}" :: Number -> Number -> Number
22Importing Types
23---------------
25To declare a new type with no constructors, use `foreign import data` and provide the kind::
27 foreign import data DOM :: *
29 foreign import document :: {
30 createElement :: String -> DOM
31 }