@@ -5,7 +5,6 @@ module Prelude
5
5
, const
6
6
, asTypeOf
7
7
, otherwise
8
- , (:), cons
9
8
, Semigroupoid , compose , (<<<), (>>>)
10
9
, Category , id
11
10
, Functor , map , (<$>), (<#>), void
@@ -116,30 +115,6 @@ asTypeOf x _ = x
116
115
otherwise :: Boolean
117
116
otherwise = true
118
117
119
- -- | Attaches an element to the front of an array, creating a new array.
120
- -- |
121
- -- | ```purescript
122
- -- | cons 1 [2, 3, 4] = [1, 2, 3, 4]
123
- -- | ```
124
- -- |
125
- -- | Note, the running time of this function is `O(n)`.
126
- foreign import cons
127
- " " "
128
- function cons(e) {
129
- return function(l) {
130
- return [e].concat(l);
131
- };
132
- }
133
- " " " :: forall a . a -> [a ] -> [a ]
134
-
135
- infixr 6 :
136
-
137
- -- | An infix alias for `cons`.
138
- -- |
139
- -- | Note, the running time of this function is `O(n)`.
140
- (:) :: forall a . a -> [a ] -> [a ]
141
- (:) = cons
142
-
143
118
infixr 9 >>>
144
119
infixr 9 <<<
145
120
@@ -199,7 +174,7 @@ class Functor f where
199
174
instance functorFn :: Functor ((-> ) r ) where
200
175
map = compose
201
176
202
- instance functorArray :: Functor [] where
177
+ instance functorArray :: Functor Array where
203
178
map = arrayMap
204
179
205
180
foreign import arrayMap
@@ -214,7 +189,7 @@ foreign import arrayMap
214
189
return result;
215
190
};
216
191
}
217
- " " " :: forall a b . (a -> b ) -> [ a ] -> [ b ]
192
+ " " " :: forall a b . (a -> b ) -> Array a -> Array b
218
193
219
194
(<$>) :: forall f a b . (Functor f ) => (a -> b ) -> f a -> f b
220
195
(<$>) = map
@@ -272,7 +247,7 @@ class (Functor f) <= Apply f where
272
247
instance applyFn :: Apply ((-> ) r ) where
273
248
apply f g x = f x (g x)
274
249
275
- instance applyArray :: Apply [] where
250
+ instance applyArray :: Apply Array where
276
251
apply = ap
277
252
278
253
(<*>) :: forall f a b . (Apply f ) => f (a -> b ) -> f a -> f b
@@ -302,7 +277,7 @@ class (Apply f) <= Applicative f where
302
277
instance applicativeFn :: Applicative ((-> ) r ) where
303
278
pure = const
304
279
305
- instance applicativeArray :: Applicative [] where
280
+ instance applicativeArray :: Applicative Array where
306
281
pure x = [x]
307
282
308
283
-- | `return` is an alias for `pure`.
@@ -358,7 +333,7 @@ class (Apply m) <= Bind m where
358
333
instance bindFn :: Bind ((-> ) r ) where
359
334
bind m f x = f (m x) x
360
335
361
- instance bindArray :: Bind [] where
336
+ instance bindArray :: Bind Array where
362
337
bind = arrayBind
363
338
364
339
foreign import arrayBind
@@ -372,7 +347,7 @@ foreign import arrayBind
372
347
return result;
373
348
};
374
349
}
375
- " " " :: forall a b . [ a ] -> (a -> [ b ] ) -> [ b ]
350
+ " " " :: forall a b . Array a -> (a -> Array b ) -> Array b
376
351
377
352
(>>=) :: forall m a b . (Monad m ) => m a -> (a -> m b ) -> m b
378
353
(>>=) = bind
@@ -391,7 +366,7 @@ class (Applicative m, Bind m) <= Monad m
391
366
392
367
instance monadFn :: Monad ((-> ) r )
393
368
394
- instance monadArray :: Monad []
369
+ instance monadArray :: Monad Array
395
370
396
371
-- | `liftM1` provides a default implementation of `(<$>)` for any
397
372
-- | [`Monad`](#monad), without using `(<$>)` as provided by the
@@ -462,7 +437,7 @@ instance semigroupOrdering :: Semigroup Ordering where
462
437
append GT _ = GT
463
438
append EQ y = y
464
439
465
- instance semigroupArray :: Semigroup [ a ] where
440
+ instance semigroupArray :: Semigroup ( Array a ) where
466
441
append = concatArray
467
442
468
443
foreign import concatString
@@ -481,7 +456,7 @@ foreign import concatArray
481
456
return xs.concat(ys);
482
457
};
483
458
}
484
- " " " :: forall a . [ a ] -> [ a ] -> [ a ]
459
+ " " " :: forall a . Array a -> Array a -> Array a
485
460
486
461
infixl 6 +
487
462
infixl 7 *
@@ -733,7 +708,7 @@ instance eqString :: Eq String where
733
708
instance eqUnit :: Eq Unit where
734
709
eq _ _ = true
735
710
736
- instance eqArray :: (Eq a ) => Eq [ a ] where
711
+ instance eqArray :: (Eq a ) => Eq ( Array a ) where
737
712
eq = eqArrayImpl (==)
738
713
739
714
instance eqOrdering :: Eq Ordering where
@@ -773,7 +748,7 @@ foreign import eqArrayImpl
773
748
};
774
749
};
775
750
}
776
- " " " :: forall a . (a -> a -> Boolean ) -> [ a ] -> [ a ] -> Boolean
751
+ " " " :: forall a . (a -> a -> Boolean ) -> Array a -> Array a -> Boolean
777
752
778
753
-- | The `Ordering` data type represents the three possible outcomes of
779
754
-- | comparing two values:
@@ -811,13 +786,39 @@ instance ordChar :: Ord Char where
811
786
instance ordUnit :: Ord Unit where
812
787
compare _ _ = EQ
813
788
814
- instance ordArray :: (Ord a ) => Ord [a ] where
815
- compare [] [] = EQ
816
- compare [] _ = LT
817
- compare _ [] = GT
818
- compare (x:xs) (y:ys) = case compare x y of
819
- EQ -> compare xs ys
820
- other -> other
789
+ instance ordArray :: (Ord a ) => Ord (Array a ) where
790
+ compare xs ys = compare 0 $ ordArrayImpl (\x y -> case compare x y of
791
+ EQ -> 0
792
+ LT -> 1
793
+ GT -> -1 ) xs ys
794
+
795
+ foreign import ordArrayImpl " " "
796
+ function ordArrayImpl(f) {
797
+ return function (xs) {
798
+ return function (ys) {
799
+ var i = 0;
800
+ var xlen = xs.length;
801
+ var ylen = ys.length;
802
+ while (i < xlen && i < ylen) {
803
+ var x = xs[i];
804
+ var y = ys[i];
805
+ var o = f(x)(y);
806
+ if (o !== 0) {
807
+ return o;
808
+ }
809
+ i++;
810
+ }
811
+ if (xlen == ylen) {
812
+ return 0;
813
+ } else if (xlen > ylen) {
814
+ return -1;
815
+ } else {
816
+ return 1;
817
+ }
818
+ };
819
+ };
820
+ }
821
+ " " " :: forall a . (a -> a -> Int ) -> Array a -> Array a -> Int
821
822
822
823
instance ordOrdering :: Ord Ordering where
823
824
compare LT LT = EQ
@@ -1053,7 +1054,7 @@ instance showString :: Show String where
1053
1054
instance showUnit :: Show Unit where
1054
1055
show _ = " unit"
1055
1056
1056
- instance showArray :: (Show a ) => Show [ a ] where
1057
+ instance showArray :: (Show a ) => Show ( Array a ) where
1057
1058
show = showArrayImpl show
1058
1059
1059
1060
instance showOrdering :: Show Ordering where
@@ -1100,4 +1101,4 @@ foreign import showArrayImpl
1100
1101
return '[' + ss.join(',') + ']';
1101
1102
};
1102
1103
}
1103
- " " " :: forall a . (a -> String ) -> [ a ] -> String
1104
+ " " " :: forall a . (a -> String ) -> Array a -> String
0 commit comments