@@ -2,7 +2,6 @@ open Base
22open Pretty
33open Out_channel
44open In_channel
5- open Lsc_err
65
76let ( let* ) x f = Result. bind x ~f
87
@@ -339,21 +338,6 @@ let fusion repl1 repl2 s1 s2 bans1 bans2 theta : star =
339338 ; bans = List. map (nbans1 @ nbans2) ~f: (fmap_ban ~f: (subst theta))
340339 }
341340
342- let apply_effect r theta : (unit, err_effect) Result.t =
343- match (r, theta) with
344- | Func ((Noisy, (_ , "print" )), _ ), [] -> Error (TooFewArgs " print" )
345- | Func ((Noisy, (_ , "print" )), _ ), _ :: _ :: _ -> Error (TooManyArgs " print" )
346- | Func ((Noisy, (_ , "print" )), _ ), [ (_, Func ((_, (Null , arg)), [] )) ] ->
347- String. strip ~drop: (fun x -> equal_char x '\"' ) arg |> output_string stdout;
348- flush stdout;
349- Ok ()
350- | Func ((Noisy, (_ , "print" )), _ ), [ (_, arg) ] ->
351- output_string stdout (string_of_ray arg);
352- flush stdout;
353- Ok ()
354- | Func ((Noisy, (_ , s )), _ ), _ -> Error (UnknownEffect s)
355- | _ -> Ok ()
356-
357341let pause () =
358342 flush stdout;
359343 let _ = input_line stdin in
@@ -384,9 +368,9 @@ let coherent_bans bans =
384368(* interaction between one selected ray and one selected action *)
385369let rec interaction ~showtrace ~queue repl1 repl2
386370 (selected_action , other_actions ) (selected_ray , other_rays , bans ) :
387- ( star list , err_effect ) Result. t =
371+ star list =
388372 match selected_action.content with
389- | [] -> Ok []
373+ | [] -> []
390374 | r' :: s' when not (is_polarised r') ->
391375 interaction ~showtrace ~queue: (r' :: queue) repl1 repl2
392376 ({ content = s'; bans }, other_actions)
@@ -405,15 +389,14 @@ let rec interaction ~showtrace ~queue repl1 repl2
405389 (selected_ray, other_rays, bans)
406390 (* if there is an actual connection between rays *)
407391 | Some theta ->
408- let * _ = apply_effect selected_ray theta in
409392 begin
410393 if showtrace then
411394 output_string stdout
412395 @@ Printf. sprintf " success with %s." (string_of_subst theta);
413396 if showtrace then pause ()
414397 end ;
415398 (* action is consumed when execution is linear *)
416- let * next =
399+ let next =
417400 interaction ~showtrace ~queue: (r' :: queue) repl1 repl2
418401 ({ content = s'; bans }, other_actions)
419402 (selected_ray, other_rays, bans)
@@ -423,29 +406,29 @@ let rec interaction ~showtrace ~queue repl1 repl2
423406 fusion repl1 repl2 other_rays other_rays' bans selected_action.bans
424407 theta
425408 in
426- let * res =
409+ let res =
427410 if coherent_bans after_fusion.bans then begin
428411 let _ =
429412 if showtrace then
430413 output_string stdout
431414 @@ Printf. sprintf " add star %s." (string_of_star after_fusion)
432415 in
433- Ok ( after_fusion :: next)
416+ after_fusion :: next
434417 end
435418 else begin
436419 if showtrace then
437420 output_string stdout
438421 @@ Printf. sprintf " result filtered out by constraint." ;
439- Ok next
422+ next
440423 end
441424 in
442425 if showtrace then pause () ;
443426 ident_counter := ! ident_counter + 2 ;
444- Ok res )
427+ res )
445428
446429(* search partner for a selected ray within a set of available actions *)
447430let search_partners ~linear ~showtrace (selected_ray , other_rays , bans ) actions
448- : ( star list * star list, err_effect) Result.t =
431+ : star list * star list =
449432 if showtrace then begin
450433 let str_ray = string_of_ray selected_ray in
451434 let str_rays = string_of_raylist other_rays in
@@ -455,29 +438,29 @@ let search_partners ~linear ~showtrace (selected_ray, other_rays, bans) actions
455438 end ;
456439 let repl1 = replace_indices ! ident_counter in
457440 let rec try_actions acc = function
458- | [] -> Ok ([] , acc)
441+ | [] -> ([] , acc)
459442 | selected_action :: other_actions ->
460443 let repl2 = replace_indices (! ident_counter + 1 ) in
461- let * res =
444+ let res =
462445 interaction ~showtrace ~queue: [] repl1 repl2
463446 (selected_action, other_actions)
464447 (selected_ray, other_rays, bans)
465448 in
466449 if (not @@ List. is_empty res) && linear then
467- let * next, new_actions = try_actions acc other_actions in
468- Ok (res @ next, new_actions)
450+ let next, new_actions = try_actions acc other_actions in
451+ (res @ next, new_actions)
469452 else
470- let * next, new_actions =
453+ let next, new_actions =
471454 try_actions (selected_action :: acc) other_actions
472455 in
473- Ok (res @ next, new_actions)
456+ (res @ next, new_actions)
474457 in
475458 try_actions [] actions
476459
477460let rec select_ray ~linear ~showtrace ~queue actions other_states
478- (selected_state , bans ) : ( star list option * star list, err_effect) Result.t =
461+ (selected_state , bans ) : star list option * star list =
479462 match selected_state with
480- | [] -> Ok (None , actions)
463+ | [] -> (None , actions)
481464 (* if unpolarized, no need to try, try other stars *)
482465 | r :: rs when not (is_polarised r) ->
483466 select_ray ~linear ~showtrace ~queue: (r :: queue) actions other_states
@@ -490,48 +473,45 @@ let rec select_ray ~linear ~showtrace ~queue actions other_states
490473 actions
491474 with
492475 (* interaction did nothing (no partner), try other rays *)
493- | Ok ([] , new_actions ) ->
476+ | ([] , new_actions ) ->
494477 select_ray ~linear ~showtrace ~queue: (selected_ray :: queue) new_actions
495478 other_states (other_rays, bans)
496479 (* interaction returns a result, keep it for the next round *)
497- | Ok (new_stars , new_actions ) -> Ok (Some new_stars, new_actions)
498- | Error e -> Error e )
480+ | (new_stars , new_actions ) -> (Some new_stars, new_actions))
499481
500482let rec select_star ~linear ~showtrace ~queue actions :
501- star list -> ( star list option * star list , err_effect ) Result. t = function
502- | [] -> Ok (None , actions)
483+ star list -> star list option * star list = function
484+ | [] -> (None , actions)
503485 (* select a state star and try finding a partner for each ray *)
504486 | selected_state :: other_states -> (
505487 match
506488 select_ray ~linear ~showtrace ~queue: [] actions other_states
507489 (selected_state.content, selected_state.bans)
508490 with
509491 (* no success with this star, try other stars *)
510- | Ok (None, new_actions ) ->
492+ | (None, new_actions ) ->
511493 select_star ~linear ~showtrace new_actions
512494 ~queue: (selected_state :: queue) other_states
513495 (* got new stars to add, construct the result for the next round *)
514- | Ok (Some new_stars , new_actions ) ->
515- Ok (Some (List. rev queue @ other_states @ new_stars), new_actions)
516- | Error e -> Error e )
496+ | (Some new_stars , new_actions ) ->
497+ (Some (List. rev queue @ other_states @ new_stars), new_actions))
517498
518499let string_of_cfg (actions , states ) : string =
519500 Printf. sprintf " >> actions: %s\n >> states: %s\n "
520501 (string_of_constellation actions)
521502 (string_of_constellation states)
522503
523504let exec ?(showtrace = false ) ?(linear = false ) mcs :
524- ( constellation , err_effect ) Result. t =
505+ constellation =
525506 (* do a sequence of rounds with a single interaction on state per round *)
526507 let rec loop ((actions , states ) as cfg ) =
527508 if showtrace then begin
528509 output_string stdout @@ string_of_cfg cfg;
529510 pause ()
530511 end ;
531512 match select_star ~linear ~showtrace ~queue: [] actions states with
532- | Ok (None, _ ) -> Ok states (* no more possible interaction *)
533- | Ok (Some res , new_actions ) -> loop (new_actions, res)
534- | Error e -> Error e
513+ | (None, _ ) -> states (* no more possible interaction *)
514+ | (Some res , new_actions ) -> loop (new_actions, res)
535515 in
536516 let cfg = extract_intspace mcs in
537517 if showtrace then
0 commit comments