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
|
2019-02-26 20:23:18 +03:00
|
|
|
Future.join f = case f of Future.Future (b, c, s, j) -> !j
|
2019-02-23 01:01:47 +03:00
|
|
|
|
|
|
|
Future.cancel : Future loc a ->{Remote loc} ()
|
2019-02-26 20:23:18 +03:00
|
|
|
Future.cancel f = case f of Future.Future (b, c, s, j) -> !c
|
2019-02-23 01:01:47 +03:00
|
|
|
|
|
|
|
Future.status : Future loc a ->{Remote loc} Status
|
2019-02-26 20:23:18 +03:00
|
|
|
Future.status f = case f of 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} ()
|
|
|
|
Future.begin f = case f of 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
|
2019-02-23 01:01:47 +03:00
|
|
|
-- step r = case r of
|
|
|
|
-- {a} -> a
|
|
|
|
-- {Remote.fork loc t -> k} ->
|
|
|
|
-- join = Right !t
|
|
|
|
-- cancel = ()
|
|
|
|
-- status = Finished
|
|
|
|
-- keepalive d = ()
|
|
|
|
-- handle step in k (Future ('join, 'cancel, 'status, keepalive))
|
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
|
2019-02-23 01:01:47 +03:00
|
|
|
-- err e = case e of
|
|
|
|
-- {a} -> Right a
|
|
|
|
-- {Error.error t -> k} ->handle err in k (Left t)
|
|
|
|
-- handle err in handle step in !r
|
|
|
|
|
|
|
|
-- > Remote.runSequential
|
|
|
|
|
|
|
|
-- use Optional Some None
|
|
|
|
-- use Either Left Right
|
|
|
|
-- Either.join : Either a (Either a b) -> Either a b
|
|
|
|
-- Either.join e = case e of
|
|
|
|
-- 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
|
|
|
|
-- case (l0, r0) of
|
|
|
|
-- (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)
|