mirror of
https://github.com/unisonweb/unison.git
synced 2024-09-11 02:25:39 +03:00
rename Vector.split to Vector.halve, add Vector.sort'
This commit is contained in:
parent
02227a56e9
commit
93c9f84b52
@ -380,16 +380,16 @@ makeBuiltins logger whnf =
|
||||
pure $ Term.vector' (Vector.reverse vs)
|
||||
op _ = fail "Vector.reverse unpossible"
|
||||
in (r, Just (I.Primop 1 op), unsafeParseType "forall a . Vector a -> Vector a", prefix "Vector.reverse")
|
||||
, let r = R.Builtin "Vector.split"
|
||||
, let r = R.Builtin "Vector.halve"
|
||||
op [v] = do
|
||||
Term.Vector' vs <- whnf v
|
||||
pure $ case Vector.null vs of
|
||||
True -> pair' (Term.vector []) (Term.vector [])
|
||||
False -> case Vector.splitAt (Vector.length vs `div` 2) vs of
|
||||
(x,y) -> pair' (Term.vector' x) (Term.vector' y)
|
||||
op _ = fail "Vector.split unpossible"
|
||||
op _ = fail "Vector.halve unpossible"
|
||||
typ = "forall a . Vector a -> (Vector a, Vector a)"
|
||||
in (r, Just (I.Primop 1 op), unsafeParseType typ, prefix "Vector.split")
|
||||
in (r, Just (I.Primop 1 op), unsafeParseType typ, prefix "Vector.halve")
|
||||
, let r = R.Builtin "Vector.at"
|
||||
op [n,vec] = do
|
||||
Term.Number' n <- whnf n
|
||||
|
@ -65,7 +65,7 @@ Vector.fold-balanced plus zero vs =
|
||||
go plus zero vs =
|
||||
if (Vector.size vs <=_Number 2)
|
||||
(Vector.fold-left plus zero vs)
|
||||
(let p = Vector.split vs;
|
||||
(let p = Vector.halve vs;
|
||||
go plus zero (1st p) `plus` go plus zero (2nd p);;);
|
||||
go plus zero vs;;
|
||||
;
|
||||
@ -76,6 +76,9 @@ Vector.all? f vs = Vector.fold-balanced and True (Vector.map f vs);
|
||||
Vector.sort : ∀ k a . Order k -> (a -> k) -> Vector a -> Vector a;
|
||||
Vector.sort ok f v = Vector.sort-keyed (f `then` Order.key ok) v;
|
||||
|
||||
Vector.sort' : ∀ a . Order a -> Vector a -> Vector a;
|
||||
Vector.sort' o = Vector.sort o identity;
|
||||
|
||||
Remote.map : ∀ a b . (a -> b) -> Remote a -> Remote b;
|
||||
Remote.map f = Remote.bind (f `then` Remote.pure);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user