session-ocaml icon indicating copy to clipboard operation
session-ocaml copied to clipboard

could not compile travel_agency.ml

Open ytakano opened this issue 5 years ago • 3 comments

I tried to compile travel_agency.ml, but I encountered an error concerning "SessionN".

$ ocamlfind ocamlc -g -thread -package session-ocaml,session-ocaml.ppx -rectypes -short-paths -c travel_agency.ml File "travel_agency.ml", line 2, characters 5-13: Error: Unbound module SessionN Hint: Did you mean Session?

I commented the line 2, but I also encountered another error concerning "SessionN".

$ head -n 2 travel_agency.ml open Session (*open SessionN*) $ ocamlfind ocamlc -g -thread -package session-ocaml,session-ocaml.ppx -rectypes -short-paths -c travel_agency.ml File "_none_", line 1: Error: Unbound module Syntax.SessionN

I also tried to compile another travel agency code described in the journal paper, but the same errors also appeared. https://www.sciencedirect.com/science/article/pii/S0167642318303289

ytakano avatar Nov 17 '18 06:11 ytakano

This is a simple example of the session types.

(* match.ml *)
open Session

let ch = new_channel ();;

let client ch =
    connect ch ~bindto:_0 >>
    [%select _0 `label] >>
    close _0;;

let server ch =
    accept ch ~bindto:_0 >>
    match%branch _0 with
    | `label -> close _0;;

Thread.create (run client) ch;;
run server ch;;

I translated this code by using rewriter as follows.

$ ocamlfind ppx_tools/rewriter ../ppx_session_ex.native match.ml > match.ppx.ml

Then I got the translated code as follows.

(* match.ppx.ml *)
open Session
let ch = new_channel () 
let client ch =
  ((connect ch ~bindto:_0) >>
     ((Syntax.SessionN._select _0) (fun x  -> `label x)))
    >> (close _0)
  
let server ch =
  (accept ch ~bindto:_0) >>
    (Syntax.SessionN._branch_start _0
       (function
        | (`label __ppx_linocaml_match_p_0,__ppx_linocaml_match_q_1) ->
            (Syntax.SessionN._branch _0)
              (__ppx_linocaml_match_p_0, __ppx_linocaml_match_q_1) (close _0) : 
       ([ `label of 'p0 ] * _) -> _))
  
;;Thread.create (run client) ch
;;run server ch

However, I could not find Syntax.SessionN in this library. It seems that Syntax.SessionN._select should be _select. What should Syntax.SessionN._branch_start and Syntax.SessionN._branch be?

ytakano avatar Nov 18 '18 12:11 ytakano

It seems that the Makefile and the examples haven't been updated in the last commit, but the previous commit seems to be able to run

fangyi-zhou avatar Nov 18 '18 14:11 fangyi-zhou

Thank you so much for information. I'll take a look.

keigoi avatar Nov 18 '18 23:11 keigoi