2019-02-23 01:01:47 +03:00
|
|
|
type Either a b = Left a | Right b
|
|
|
|
type Status = Running | Finished | Canceled | Error Error
|
|
|
|
type Duration = Seconds Nat
|
|
|
|
-- type Abilities e = Abilities {e}
|
|
|
|
|
2019-02-26 20:23:18 +03:00
|
|
|
ability Remote loc where
|
|
|
|
fork : loc {e}
|
|
|
|
-> '{e} a
|
|
|
|
-> {Remote loc} Future loc a
|
|
|
|
|
|
|
|
forkRegistered : (Future loc a -> {e2} ()) -> loc {e} -> '{e} a
|
|
|
|
-> {Remote loc, e2} Future loc a
|
|
|
|
forkRegistered register loc t =
|
|
|
|
future = Remote.fork loc t
|
|
|
|
register future
|
|
|
|
Future.begin future
|
|
|
|
future
|
2019-02-23 01:01:47 +03:00
|
|
|
|
|
|
|
|
2019-02-26 20:23:18 +03:00
|
|
|
ability Error e where error : e ->{Error e} ()
|
|
|
|
|
2019-02-23 01:01:47 +03:00
|
|
|
type Future loc a = Future
|
2019-02-26 20:23:18 +03:00
|
|
|
('{Remote loc} () -- begin
|
|
|
|
,'{Remote loc} () -- cancel
|
|
|
|
,'{Remote loc} Status -- status
|
|
|
|
,'{Remote loc, Error Future.Error} a -- join
|
|
|
|
)
|
|
|
|
type Future.Error = UnknownFuture | UnreachableLocation | UnresponsiveLocation | Terminated | AbilityCheckFailure
|
|
|
|
|
|
|
|
-- Ability.check : Abilities {a} -> Request {b} x -> Boolean
|
|
|
|
-- Ability.check = _
|
|
|
|
|
|
|
|
-- Remote.server : (loc {e} -> {e} a) -> {e} a
|
|
|
|
-- Remote.server computation =
|
2019-02-23 01:01:47 +03:00
|
|
|
|
|
|
|
Future.join : Future loc a ->{Remote loc, Error Future.Error} a
|
2020-02-22 02:48:12 +03:00
|
|
|
Future.join = cases Future.Future (b, c, s, j) -> !j
|
2019-02-23 01:01:47 +03:00
|
|
|
|
|
|
|
Future.cancel : Future loc a ->{Remote loc} ()
|
2020-02-22 02:48:12 +03:00
|
|
|
Future.cancel = cases Future.Future (b, c, s, j) -> !c
|
2019-02-23 01:01:47 +03:00
|
|
|
|
|
|
|
Future.status : Future loc a ->{Remote loc} Status
|
2020-02-22 02:48:12 +03:00
|
|
|
Future.status = cases Future.Future (b, c, s, j) -> !s
|
2019-02-23 01:01:47 +03:00
|
|
|
|
2019-02-26 20:23:18 +03:00
|
|
|
Future.begin : Future loc a ->{Remote loc} ()
|
2020-02-22 02:48:12 +03:00
|
|
|
Future.begin = cases Future.Future (b, c, s, j) -> !b
|
2019-02-23 01:01:47 +03:00
|
|
|
|
|
|
|
|
|
|
|
type UnitLoc e = UnitLoc
|
|
|
|
|
|
|
|
-- Remote.runSequential : '{Remote UnitLoc, Error e} a -> Either e a
|
|
|
|
-- Remote.runSequential r =
|
rename Builtins in initial namespace construction, and update tests
- () -> Unit
- ().() -> Unit.Unit
- Pair -> Tuple
- Pair.Pair -> Tuple.Cons
- Sequence -> List
- Effect -> Request
- {Int,Nat,Float,Text}.{==,<,<=,>,>=} -> {Int,Nat,Float,Text}.{eq,lt,lteq,gt,gteq}
- mark Text.!= as a deprecated builtin
2019-08-22 23:34:12 +03:00
|
|
|
-- step : Request {Remote UnitLoc} a -> a
|
2020-02-22 02:48:12 +03:00
|
|
|
-- step = cases
|
2019-02-23 01:01:47 +03:00
|
|
|
-- {a} -> a
|
|
|
|
-- {Remote.fork loc t -> k} ->
|
|
|
|
-- join = Right !t
|
|
|
|
-- cancel = ()
|
|
|
|
-- status = Finished
|
|
|
|
-- keepalive d = ()
|
2020-02-22 03:05:59 +03:00
|
|
|
-- handle k (Future ('join, 'cancel, 'status, keepalive)) with step
|
rename Builtins in initial namespace construction, and update tests
- () -> Unit
- ().() -> Unit.Unit
- Pair -> Tuple
- Pair.Pair -> Tuple.Cons
- Sequence -> List
- Effect -> Request
- {Int,Nat,Float,Text}.{==,<,<=,>,>=} -> {Int,Nat,Float,Text}.{eq,lt,lteq,gt,gteq}
- mark Text.!= as a deprecated builtin
2019-08-22 23:34:12 +03:00
|
|
|
-- err : Request {Error e} a -> Either e a
|
2020-02-22 02:48:12 +03:00
|
|
|
-- err = cases
|
2019-02-23 01:01:47 +03:00
|
|
|
-- {a} -> Right a
|
2020-02-22 03:05:59 +03:00
|
|
|
-- {Error.error t -> k} ->handle k (Left t) with err
|
|
|
|
-- handle handle !r with step with err
|
2019-02-23 01:01:47 +03:00
|
|
|
|
|
|
|
-- > Remote.runSequential
|
|
|
|
|
|
|
|
-- use Optional Some None
|
|
|
|
-- use Either Left Right
|
|
|
|
-- Either.join : Either a (Either a b) -> Either a b
|
2020-02-22 02:48:12 +03:00
|
|
|
-- Either.join = cases
|
2019-02-23 01:01:47 +03:00
|
|
|
-- Left a -> Left a
|
|
|
|
-- Right e -> e
|
|
|
|
--
|
|
|
|
-- parMergeSort : (a -> a -> Boolean) -> [a] ->{Remote UnitLoc, Error} [a]
|
|
|
|
-- parMergeSort (<) as =
|
|
|
|
-- -- merge : [a] -> [a] -> [a] -> [a]
|
|
|
|
-- merge z l r =
|
|
|
|
-- l0 = at 0 l
|
|
|
|
-- r0 = at 0 r
|
2020-02-22 02:48:12 +03:00
|
|
|
-- match (l0, r0) with
|
2019-02-23 01:01:47 +03:00
|
|
|
-- (None, _) -> z ++ r
|
|
|
|
-- (_, None) -> z ++ l
|
|
|
|
-- (Some l0, Some r0) ->
|
|
|
|
-- if l0 < r0
|
|
|
|
-- then merge (z `snoc` l0) (drop 1 l) r
|
|
|
|
-- else merge (z `snoc` r0) l (drop 1 r)
|
|
|
|
-- split = size as / 2
|
|
|
|
-- if split == 0 then as
|
|
|
|
-- else
|
|
|
|
-- fl = Remote.fork UnitLoc '(parMergeSort (<) (take split as))
|
|
|
|
-- fr = Remote.fork UnitLoc '(parMergeSort (<) (drop split as))
|
|
|
|
-- merge [] (Future.join fl) (Future.join fr)
|