forked from faylang/fay
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFFI.hs
51 lines (43 loc) · 1.29 KB
/
FFI.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE TypeSynonymInstances #-}
-- | The internal FFI module.
module Fay.FFI
(Fay
,Nullable (..)
,Defined (..)
,Ptr
,Automatic
,ffi)
where
import Data.String (IsString)
import Fay.Types
import Prelude (Bool, Char, Double, Int, Maybe, String, error)
-- | Values that may be null
-- Nullable x decodes to x, Null decodes to null.
data Nullable a = Nullable a | Null
-- | Values that may be undefined
-- Defined x encodes to x, Undefined decodes to undefined.
-- An undefined property in a record will be removed when encoding.
data Defined a = Defined a | Undefined
-- | Do not serialize the specified type. This is useful for, e.g.
--
-- > foo :: String -> String
-- > foo = ffi "%1"
--
-- This would normally serialize and unserialize the string, for no
-- reason, in this case. Instead:
--
-- > foo :: Ptr String -> Ptr String
--
-- Will just give an identity function.
type Ptr a = a
-- | The opposite of "Ptr". Serialize the specified polymorphic type.
--
-- > foo :: Automatic a -> String
--
type Automatic a = a
-- | Declare a foreign action.
ffi :: IsString s
=> s -- ^ The foreign value.
-> a -- ^ Bottom.
ffi = error "Fay.FFI.ffi: Used foreign function outside a JS engine context."