@@ -2,9 +2,7 @@ module JSON.Internal where
22
33import Prelude
44
5- import Data.Either (Either )
65import Data.Function.Uncurried (Fn2 , Fn3 , Fn4 , Fn7 , runFn2 , runFn7 )
7- import Data.Maybe (Maybe )
86import Data.Tuple (Tuple (..))
97
108-- | A type that represents all varieties of JSON value.
@@ -54,17 +52,22 @@ foreign import toArray :: JArray -> Array JSON
5452-- | Converts an `Array` of `JSON` values into a `JArray`.
5553foreign import fromArray :: Array JSON -> JArray
5654
55+ -- | An empty `JArray`.
56+ foreign import empty :: JArray
57+
5758instance Eq JArray where
58- eq x y = eq (toArray x) (toArray y)
59+ eq xs ys
60+ | length xs == length ys = eq (toArray xs) (toArray ys)
61+ | otherwise = false
5962
6063instance Ord JArray where
6164 compare x y = compare (toArray x) (toArray y)
6265
6366instance Semigroup JArray where
64- append x y = fromArray (append (toArray x) (toArray y))
67+ append xs ys = runFn2 _append xs ys
6568
6669instance Monoid JArray where
67- mempty = fromArray []
70+ mempty = empty
6871
6972-- | A type that represents JSON objects. Similar to the JSON type, this is not a PureScript type,
7073-- | but represents the underlying representation for JSON objects.
@@ -77,11 +80,12 @@ instance Ord JObject where
7780 compare x y = compare (runFn2 _entries Tuple x) (runFn2 _entries Tuple y)
7881
7982foreign import _parse
80- :: Fn3
81- (forall a b . a -> Either a b )
82- (forall a b . b -> Either a b )
83+ :: forall f
84+ . Fn3
85+ (forall a b . a -> f a b )
86+ (forall a b . b -> f a b )
8387 String
84- (Either String JSON )
88+ (f String JSON )
8589
8690foreign import _fromNumberWithDefault :: Fn2 Int Number JSON
8791
@@ -102,18 +106,37 @@ foreign import _insert :: Fn3 String JSON JObject JObject
102106foreign import _delete :: Fn2 String JObject JObject
103107
104108foreign import _fromEntries
105- :: Fn3
106- (forall x y . Tuple x y -> x )
107- (forall x y . Tuple x y -> y )
108- (Prim.Array (Tuple String JSON ))
109+ :: forall f
110+ . Fn3
111+ (forall x y . f x y -> x )
112+ (forall x y . f x y -> y )
113+ (Prim.Array (f String JSON ))
109114 JObject
110115
111116foreign import _entries :: forall c . Fn2 (String -> JSON -> c ) JObject (Prim.Array c )
112117
113118foreign import _lookup
114- :: Fn4
115- (forall a . Maybe a )
116- (forall a . a -> Maybe a )
119+ :: forall f
120+ . Fn4
121+ (forall a . f a )
122+ (forall a . a -> f a )
117123 String
118124 JObject
119- (Maybe JSON )
125+ (f JSON )
126+
127+ foreign import _index
128+ :: forall f
129+ . Fn4
130+ (forall a . f a )
131+ (forall a . a -> f a )
132+ Int
133+ JArray
134+ (f JSON )
135+
136+ foreign import length :: JArray -> Int
137+
138+ foreign import _append
139+ :: Fn2
140+ JArray
141+ JArray
142+ JArray
0 commit comments