Skip to content

Commit

Permalink
Update to the latest version of coq:io
Browse files Browse the repository at this point in the history
  • Loading branch information
clarus committed Mar 23, 2015
1 parent b3a5232 commit 9ae1c29
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions src/Main.v
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ Import ListNotations.
Import C.Notations.

(** The classic Hello World program. *)
Definition hello_world (argv : list LString.t) : C.t System.effects unit :=
Definition hello_world (argv : list LString.t) : C.t System.effect unit :=
System.log (LString.s "Hello world!").

(** Ask for the user name and answer hello. *)
Definition your_name (argv : list LString.t) : C.t System.effects unit :=
Definition your_name (argv : list LString.t) : C.t System.effect unit :=
do! System.log (LString.s "What is your name?") in
let! name := System.read_line in
match name with
Expand All @@ -21,7 +21,7 @@ Definition your_name (argv : list LString.t) : C.t System.effects unit :=

(** A concurrent Hello World. May print "Hello World" or "World Hello". *)
Definition concurrent_hello_world (argv : list LString.t)
: C.t System.effects unit :=
: C.t System.effect unit :=
let! _ : unit * unit := join
(System.log (LString.s "Hello"))
(System.log (LString.s "World")) in
Expand All @@ -34,34 +34,36 @@ Extraction "extraction/main" main.

(** Specifications. *)
Module Run.
Import Io.Spec.

(** The Hello World program only says hello. *)
Definition hello_world_ok (argv : list LString.t)
: Run.t (hello_world argv) tt.
apply (Run.log_ok (LString.s "Hello world!")).
: Spec.t (hello_world argv) tt.
apply (Spec.log_ok (LString.s "Hello world!")).
Defined.

(** The Your Name program answers something when you give your name. *)
Definition your_name_ok (argv : list LString.t) (name : LString.t)
: Run.t (your_name argv) tt.
apply (Run.Let (Run.log_ok _)).
apply (Run.Let (Run.read_line_ok name)).
apply (Run.log_ok _).
: Spec.t (your_name argv) tt.
apply (Let (Spec.log_ok _)).
apply (Let (Spec.read_line_ok name)).
apply (Spec.log_ok _).
Defined.

(** The Your Name program does nothing more in case of error on stdin. *)
Definition your_name_error (argv : list LString.t)
: Run.t (your_name argv) tt.
apply (Run.Let (Run.log_ok _)).
apply (Run.Let Run.read_line_error).
apply Run.Ret.
: Spec.t (your_name argv) tt.
apply (Let (Spec.log_ok _)).
apply (Let Spec.read_line_error).
apply Ret.
Defined.

(** The concurrent Hello World program says both "Hello" and "World". *)
Definition concurrent_hello_world_ok (argv : list LString.t)
: Run.t (concurrent_hello_world argv) tt.
apply (Run.Let (Run.Join
(Run.log_ok (LString.s "Hello"))
(Run.log_ok (LString.s "World")))).
apply Run.Ret.
: Spec.t (concurrent_hello_world argv) tt.
apply (Let (Join
(Spec.log_ok (LString.s "Hello"))
(Spec.log_ok (LString.s "World")))).
apply Ret.
Defined.
End Run.

0 comments on commit 9ae1c29

Please sign in to comment.