on master help sign in
Add Encode.int and (==>)
commit6b96fe702b3e0de53fb7898442e269d2c9709e94 authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 3 Apr 2017, 19:50 (10 years ago) parent6b92297
1 file changed+20
src/Json/Encode.hs+20
src/Json/Encode.hs+20
@@ -9,8 +9,10 @@ module Json.Encode
99 , text
1010 , string
1111 , bool
12+ , int
1213 , dict
1314 , list
15+ , (==>)
1416 )
1517 where
1618
@@ -34,6 +36,7 @@ data Value
3436 | Object [(String, Value)]
3537 | String B.Builder
3638 | Boolean Bool
39+ | Integer Int
3740
3841
3942array :: [Value] -> Value
@@ -61,6 +64,11 @@ bool =
6164 Boolean
6265
6366
67+int :: Int -> Value
68+int =
69+ Integer
70+
71+
6472dict :: (k -> String) -> (v -> Value) -> Map.Map k v -> Value
6573dict encodeKey encodeValue pairs =
6674 Object $ map (encodeKey *** encodeValue) (Map.toList pairs)
@@ -72,6 +80,15 @@ list encodeEntry entries =
7280
7381
7482
83+-- HELPERS
84+
85+
86+(==>) :: a -> b -> (a, b)
87+(==>) a b =
88+ (a, b)
89+
90+
91+
7592-- WRITE TO FILE
7693
7794
@@ -111,6 +128,9 @@ encodeHelp indent value =
111128 Boolean boolean ->
112129 B.string7 (if boolean then "true" else "false")
113130
131+ Integer n ->
132+ B.intDec n
133+
114134
115135
116136-- ENCODE ARRAY