git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Update ffi.rst
3b67c31Phil Freeman
docs/source/ffi.rst+27−13
@@ -1,17 +1,31 @@
1−## Foreign Function Interface
1+Foreign Function Interface
2+==========================
2
3
3−The `foreign import` keyword declares a value which is defined in Javascript, and its type:
4+Importing Values
5+----------------
4
6
5−```haskell
7+The `foreign import` keyword declares a value which is defined in Javascript, and its type::
6−foreign import pow :: (Number, Number) -> Number
7−```
8
8
9−To declare a new type with no constructors, use `foreign import data` and provide the kind:
9+ foreign import pow :: Number -> Number -> Number
10
10
11−```haskell
11+Inline Javascript
12−foreign import data IO :: * -> *
12+-----------------
13−
13+
14+A 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::
15+
16+ foreign import pow "function pow(n) {\
17+ \ return function(p) {\
18+ \ return Math.pow(n, p);\
19+ \ };\
20+ \}" :: Number -> Number -> Number
21+
22+Importing Types
23+---------------
24+
25+To declare a new type with no constructors, use `foreign import data` and provide the kind::
26+
27+ foreign import data DOM :: *
28+
14−foreign import console :: {
29+ foreign import document :: {
15− log :: String -> IO {}
30+ createElement :: String -> DOM
16−}
31+ }
17−```