Skip to content

Commit f4c19da

Browse files
committed
refactor: Replace "prot" with "fun_ty" as suggested by @yurug
1 parent 1cae522 commit f4c19da

File tree

8 files changed

+151
-143
lines changed

8 files changed

+151
-143
lines changed

demo-repository/exercises/demo/test.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,16 @@ let () =
2222
Section
2323
([ Text "Function:" ; Code "divide" ],
2424
test_function_against_solution
25-
[%prot: int -> int -> int] "divide"
25+
[%funty: int -> int -> int] "divide"
2626
[ 16 @:!! 4 ;
2727
12 @:!! 5 ;
2828
3 @:!! 0 ]) ;
2929
Section
3030
([ Text "Function:" ; Code "sum3" ],
3131
test_function_against_solution
32-
~gen:2 (* only 2 random test cases *)
33-
[%prot: int -> int -> int -> int] (* function type *)
34-
"sum3" (* function name *)
32+
~gen:2 (* only 2 random test cases *)
33+
[%funty: int -> int -> int -> int] (* function type *)
34+
"sum3" (* function name *)
3535
(* list of additional, explicit test cases *)
3636
[ 10 @: 20 @:!! 30 ;
3737
-1 @: -2 @:!! -3 ])

src/grader/dune

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@
104104
%{ocaml-config:standard_library}/compiler-libs/parse.cmi)
105105
(:generated-cmis
106106
../ppx-metaquot/.ty.objs/ty.cmi
107-
../ppx-metaquot/.prot.objs/prot.cmi
107+
../ppx-metaquot/.fun_ty.objs/fun_ty.cmi
108108
.testing.objs/introspection_intf.cmi
109109
.learnocaml_report.objs/learnocaml_report.cmi
110110
.testing.objs/test_lib.cmi))

src/grader/test_lib.ml

Lines changed: 78 additions & 78 deletions
Large diffs are not rendered by default.

src/grader/test_lib.mli

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,17 +1097,17 @@ module type S = sig
10971097
can be returned. *)
10981098
val result : (unit -> 'a) -> 'a result
10991099

1100-
(** Helper notations for [Prot.args] *)
1100+
(** Helper notations for [Fun_ty.args] *)
11011101
val (!!) :
11021102
'a ->
1103-
('a -> 'ret, 'a -> unit, 'ret) Prot.args
1103+
('a -> 'ret, 'a -> unit, 'ret) Fun_ty.args
11041104
val (@:) :
11051105
'a ->
1106-
('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args ->
1107-
('a -> 'ar -> 'row, 'a -> 'ar -> 'urow, 'ret) Prot.args
1106+
('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args ->
1107+
('a -> 'ar -> 'row, 'a -> 'ar -> 'urow, 'ret) Fun_ty.args
11081108
val (@:!!) :
11091109
'a -> 'b ->
1110-
('a -> 'b -> 'ret, 'a -> 'b -> unit, 'ret) Prot.args
1110+
('a -> 'b -> 'ret, 'a -> 'b -> unit, 'ret) Fun_ty.args
11111111

11121112
(** {2 Lookup functions} *)
11131113

@@ -1135,16 +1135,16 @@ module type S = sig
11351135
?test_stdout: io_tester ->
11361136
?test_stderr: io_tester ->
11371137
?before :
1138-
(('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args ->
1138+
(('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args ->
11391139
unit) ->
11401140
?after :
1141-
(('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args ->
1141+
(('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args ->
11421142
('ret * string * string) ->
11431143
('ret * string * string) ->
11441144
Learnocaml_report.t) ->
1145-
(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) Prot.prot ->
1145+
(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) Fun_ty.fun_ty ->
11461146
('ar -> 'row) lookup ->
1147-
(('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args * (unit -> 'ret)) list ->
1147+
(('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args * (unit -> 'ret)) list ->
11481148
Learnocaml_report.t
11491149

11501150
(** [test_function_against ~gen ~test ~test_stdout ~test_stderr
@@ -1155,19 +1155,19 @@ module type S = sig
11551155
?test_stdout: io_tester ->
11561156
?test_stderr: io_tester ->
11571157
?before_reference :
1158-
(('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args -> unit) ->
1158+
(('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args -> unit) ->
11591159
?before_user :
1160-
(('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args -> unit) ->
1160+
(('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args -> unit) ->
11611161
?after :
1162-
(('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args ->
1162+
(('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args ->
11631163
('ret * string * string) ->
11641164
('ret * string * string) ->
11651165
Learnocaml_report.t) ->
11661166
?sampler:
1167-
(unit -> ('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args) ->
1168-
(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) Prot.prot ->
1167+
(unit -> ('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args) ->
1168+
(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) Fun_ty.fun_ty ->
11691169
('ar -> 'row) lookup -> ('ar -> 'row) lookup ->
1170-
('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args list ->
1170+
('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args list ->
11711171
Learnocaml_report.t
11721172

11731173
(** [test_function_against_solution ~gen ~test ~test_stdout ~test_stderr
@@ -1178,27 +1178,27 @@ module type S = sig
11781178
?test_stdout: io_tester ->
11791179
?test_stderr: io_tester ->
11801180
?before_reference:
1181-
(('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args -> unit) ->
1181+
(('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args -> unit) ->
11821182
?before_user:
1183-
(('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args -> unit) ->
1183+
(('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args -> unit) ->
11841184
?after:
1185-
(('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args ->
1185+
(('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args ->
11861186
'ret * string * string ->
11871187
'ret * string * string ->
11881188
Learnocaml_report.item list) ->
11891189
?sampler:
1190-
(unit -> ('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args) ->
1191-
(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) Prot.prot ->
1190+
(unit -> ('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args) ->
1191+
(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) Fun_ty.fun_ty ->
11921192
string ->
1193-
('ar -> 'row, 'ar -> 'urow, 'ret) Prot.args list ->
1193+
('ar -> 'row, 'ar -> 'urow, 'ret) Fun_ty.args list ->
11941194
Learnocaml_report.item list
11951195

11961196
(** Helper notation to test pure functions.
11971197
11981198
[p ==> r] is the pair [(p, fun () -> r)].
11991199
12001200
Example: [test_function prot
1201-
(lookup_student (ty_of_prot prot) name)
1201+
(lookup_student (ty_of_fun_ty prot) name)
12021202
[1 @: 2 @: 3 @: 4 @:!! 5 ==> 15; ... ==> ...]] *)
12031203
val (==>) : 'params -> 'ret -> 'params * (unit -> 'ret)
12041204
end

src/ppx-metaquot/dune

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
(library
2424
(name learnocaml_ppx_metaquot)
2525
(wrapped false)
26-
(libraries learnocaml_ppx_metaquot_lib ty prot ocaml-migrate-parsetree)
26+
(libraries learnocaml_ppx_metaquot_lib ty fun_ty ocaml-migrate-parsetree)
2727
(modules Ppx_metaquot_main)
2828
(kind ppx_rewriter)
2929
)
@@ -37,9 +37,9 @@
3737
)
3838

3939
(library
40-
(name prot)
40+
(name fun_ty)
4141
(wrapped false)
4242
(library_flags :standard -linkall)
43-
(modules Prot)
43+
(modules Fun_ty)
4444
(libraries ty)
4545
)

src/ppx-metaquot/prot.ml renamed to src/ppx-metaquot/fun_ty.ml

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,30 @@ type (_, _, _) args =
1515
let last x = Last x
1616
let arg x r = Arg (x, r)
1717

18-
let rec apply : type p a c r. (p -> a) -> (p -> a, p -> c, r) args -> r = fun f x ->
18+
let rec apply
19+
: type p a c r. (p -> a) -> (p -> a, p -> c, r) args -> r = fun f x ->
1920
match x with
2021
| Last x -> f x
2122
| Arg (x, Last r) -> (f x) r
2223
| Arg (x, Arg (y, r)) -> apply (f x) (Arg (y, r))
2324

24-
(* Usage: arg_ty [%ty: int] @@ arg_ty [%ty: string] @@ last_ty [%ty: bool] [%ty: unit] *)
25-
type (_, _, _) prot =
26-
| Last_ty : 'a Ty.ty * 'r Ty.ty -> (('a -> 'r) Ty.ty, 'a -> unit, 'r) prot
27-
| Arg_ty : 'a Ty.ty * (('b -> 'c) Ty.ty, 'b -> 'd, 'r) prot -> (('a -> 'b -> 'c) Ty.ty, 'a -> 'b -> 'd, 'r) prot
25+
(* Usage:
26+
arg_ty [%ty: int] @@ arg_ty [%ty: string] @@ last_ty [%ty: bool] [%ty: unit]
27+
*)
28+
type (_, _, _) fun_ty =
29+
| Last_ty : 'a Ty.ty * 'r Ty.ty -> (('a -> 'r) Ty.ty, 'a -> unit, 'r) fun_ty
30+
| Arg_ty : 'a Ty.ty * (('b -> 'c) Ty.ty, 'b -> 'd, 'r) fun_ty ->
31+
(('a -> 'b -> 'c) Ty.ty, 'a -> 'b -> 'd, 'r) fun_ty
2832

2933
let last_ty x r = Last_ty (x, r)
3034
let arg_ty x r = Arg_ty (x, r)
3135

32-
let rec ty_of_prot : type p a c r. ((p -> a) Ty.ty, p -> c, r) prot -> (p -> a) Ty.ty = function
36+
let rec ty_of_fun_ty
37+
: type p a c r. ((p -> a) Ty.ty, p -> c, r) fun_ty -> (p -> a) Ty.ty =
38+
function
3339
| Last_ty (a, b) -> Ty.curry a b
3440
| Arg_ty (x, Last_ty (l, r)) -> Ty.curry x (Ty.curry l r)
35-
| Arg_ty (x, Arg_ty (y, r)) -> Ty.curry x (ty_of_prot (Arg_ty (y, r)))
41+
| Arg_ty (x, Arg_ty (y, r)) -> Ty.curry x (ty_of_fun_ty (Arg_ty (y, r)))
3642

3743
let rec get_ret_ty
3844
: type p a c r. (p -> a) Ty.ty -> (p -> a, p -> c, r) args -> r Ty.ty =
@@ -55,7 +61,8 @@ end
5561

5662
module Make (M : S) = struct
5763
let rec print
58-
: type p a c r. ((p -> a) Ty.ty, p -> c, r) prot -> Format.formatter -> (p -> a, p -> c, r) args -> unit =
64+
: type p a c r. ((p -> a) Ty.ty, p -> c, r) fun_ty ->
65+
Format.formatter -> (p -> a, p -> c, r) args -> unit =
5966
fun t ppf x ->
6067
match t, x with
6168
| Last_ty (arg_ty, _), Last x ->
@@ -72,7 +79,8 @@ module Make (M : S) = struct
7279
| Last_ty (_, _), Arg (_, _) -> .
7380

7481
let rec get_sampler
75-
: type p a c r. ((p -> a) Ty.ty, p -> c, r) prot -> unit -> (p -> a, p -> c, r) args =
82+
: type p a c r. ((p -> a) Ty.ty, p -> c, r) fun_ty -> unit ->
83+
(p -> a, p -> c, r) args =
7684
fun wit ->
7785
match wit with
7886
| Last_ty (x, _) ->

src/ppx-metaquot/prot.mli renamed to src/ppx-metaquot/fun_ty.mli

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
(** Library of heterogeneous, nonempty lists and their corresponding types.
1010
11-
let p = [%prot: int -> bool]
11+
let p = [%funty: int -> bool]
1212
13-
val p : ((int -> bool) Ty.ty, int -> unit, bool) Prot.prot = <abstr>
13+
val p : ((int -> bool) Ty.ty, int -> unit, bool) Fun_ty.fun_ty = <abstr>
1414
*)
1515

1616
(** The type of arguments, represented as heterogeneous lists.
@@ -36,18 +36,18 @@ val apply : ('ar -> 'row) -> ('ar -> 'row, 'ar -> 'urow, 'ret) args -> 'ret
3636
[arg_ty [%ty: int]
3737
@@ arg_ty [%ty: string] @@ last_ty [%ty: bool] [%ty: unit]]
3838
*)
39-
type ('arrow, 'uarrow, 'ret) prot
39+
type ('arrow, 'uarrow, 'ret) fun_ty
4040
val last_ty :
4141
'a Ty.ty ->
4242
'ret Ty.ty ->
43-
(('a -> 'ret) Ty.ty, 'a -> unit, 'ret) prot
43+
(('a -> 'ret) Ty.ty, 'a -> unit, 'ret) fun_ty
4444
val arg_ty :
4545
'a Ty.ty ->
46-
(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) prot ->
47-
(('a -> 'ar -> 'row) Ty.ty, ('a -> 'ar -> 'urow), 'ret) prot
46+
(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) fun_ty ->
47+
(('a -> 'ar -> 'row) Ty.ty, ('a -> 'ar -> 'urow), 'ret) fun_ty
4848

49-
val ty_of_prot :
50-
(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) prot -> ('ar -> 'row) Ty.ty
49+
val ty_of_fun_ty :
50+
(('ar -> 'row) Ty.ty, 'ar -> 'urow, 'ret) fun_ty -> ('ar -> 'row) Ty.ty
5151
val get_ret_ty :
5252
('p -> 'a) Ty.ty -> ('p -> 'a, 'p -> 'c, 'ret) args -> 'ret Ty.ty
5353

@@ -58,10 +58,10 @@ end
5858

5959
module Make : functor (M : S) -> sig
6060
val print :
61-
(('p -> 'a) Ty.ty, 'p -> 'c, 'r) prot ->
61+
(('p -> 'a) Ty.ty, 'p -> 'c, 'r) fun_ty ->
6262
Format.formatter -> ('p -> 'a, 'p -> 'c, 'r) args -> unit
6363
val get_sampler :
64-
(('p -> 'a) Ty.ty, 'p -> 'c, 'r) prot ->
64+
(('p -> 'a) Ty.ty, 'p -> 'c, 'r) fun_ty ->
6565
unit -> ('p -> 'a, 'p -> 'c, 'r) args
6666
end
6767

src/ppx-metaquot/ppx_metaquot.ml

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,30 +207,30 @@ module Main : sig val expander: string list -> Ast_mapper.mapper end = struct
207207
[Nolabel, tyexpr])
208208
(Typ.constr ty_id [cty])
209209

210-
let prot_of this l e =
210+
let fun_ty_of this l e =
211211
(* Naming convention: ty:=Ty.ty, cty:=core_type, ety:=expression *)
212212
let glob_cty = get_typ l e in
213213
match glob_cty with
214214
| { Parsetree.ptyp_desc = Parsetree.Ptyp_arrow (_, arg0, next) ; _ } ->
215215
(* OK: The type expression is an arrow type *)
216216
(* Recursion over [core_type]s: *)
217-
let rec get_prot_of arg0 next =
217+
let rec get_fun_ty_of arg0 next =
218218
match next with
219219
| { Parsetree.ptyp_desc = Parsetree.Ptyp_arrow (_, arg', next') ; _ } ->
220-
let prot_next, ucty, ret = get_prot_of arg' next' in
221-
(* Arg_ty (arg0, prot_next) : (('a -> 'b -> 'c) Ty.ty, 'a -> 'b -> 'd, 'r) *)
222-
let cons_arg_id = Location.mknoloc Longident.(Ldot (Lident "Prot", "arg_ty")) in
220+
let fun_ty_next, ucty, ret = get_fun_ty_of arg' next' in
221+
(* Arg_ty (arg0, fun_ty_next) : (('a -> 'b -> 'c) Ty.ty, 'a -> 'b -> 'd, 'r) *)
222+
let cons_arg_id = Location.mknoloc Longident.(Ldot (Lident "Fun_ty", "arg_ty")) in
223223
let arg0_ety = ty_of this arg0 in
224224
let ucty = Typ.arrow Nolabel arg0 ucty in
225225
(Exp.apply
226226
(Exp.apply
227227
(Exp.ident cons_arg_id)
228228
[Nolabel, arg0_ety])
229-
[Nolabel, prot_next],
229+
[Nolabel, fun_ty_next],
230230
ucty, ret)
231231
| _ ->
232-
(* Last_ty (arg0, next) : (('a -> 'r) Ty.ty, 'a -> unit, 'r) prot *)
233-
let cons_last_id = Location.mknoloc Longident.(Ldot (Lident "Prot", "last_ty")) in
232+
(* Last_ty (arg0, next) : (('a -> 'r) Ty.ty, 'a -> unit, 'r) fun_ty *)
233+
let cons_last_id = Location.mknoloc Longident.(Ldot (Lident "Fun_ty", "last_ty")) in
234234
let arg0_ety = ty_of this arg0 in
235235
let next_ety = ty_of this next in
236236
let unit_id = Location.mknoloc (Longident.Lident "unit") in
@@ -244,15 +244,15 @@ module Main : sig val expander: string list -> Ast_mapper.mapper end = struct
244244
ucty, next)
245245
in
246246
(* Main branch *)
247-
let prot_next, ucty, ret = get_prot_of arg0 next in
248-
(* prot_next : (('a -> 'b -> 'r) Ty.ty, 'a -> 'b -> unit, 'r) [typecast] *)
249-
let prot_id = Location.mknoloc Longident.(Ldot (Lident "Prot", "prot")) in
247+
let fun_ty_next, ucty, ret = get_fun_ty_of arg0 next in
248+
(* fun_ty_next : (('a -> 'b -> 'r) Ty.ty, 'a -> 'b -> unit, 'r) [typecast] *)
249+
let fun_ty_id = Location.mknoloc Longident.(Ldot (Lident "Fun_ty", "fun_ty")) in
250250
let ty_id = Location.mknoloc Longident.(Ldot (Lident "Ty", "ty")) in
251251
let glob_cty_ty = Typ.constr ty_id [glob_cty] in
252252
Exp.constraint_
253-
prot_next
254-
(Typ.constr prot_id [glob_cty_ty; ucty; ret])
255-
| _ -> invalid_arg "prot_of: not an arrow type"
253+
fun_ty_next
254+
(Typ.constr fun_ty_id [glob_cty_ty; ucty; ret])
255+
| _ -> invalid_arg "fun_ty_of: not an arrow type"
256256
(* ------ </edited for learn-ocaml> ------ *)
257257

258258
let expander _args =
@@ -276,8 +276,8 @@ module Main : sig val expander: string list -> Ast_mapper.mapper end = struct
276276
| Pexp_extension({txt="ty";loc=l}, e) ->
277277
let ty = get_typ l e in
278278
ty_of this ty
279-
| Pexp_extension({txt="prot";loc=l}, e) ->
280-
prot_of this l e
279+
| Pexp_extension({txt="funty";loc=l}, e) ->
280+
fun_ty_of this l e
281281
(* ------ </edited for learn-ocaml> ------ *)
282282
| _ ->
283283
super.expr this e

0 commit comments

Comments
 (0)