I try to learn OCaml and implement tiger compiler following tiger book;
right now I meet this problem;
I implement translate.mli with the below code;
module type TRANSLATE = sig
module Frame: Frame.FRAME
module Temp = Frame.Temp
type exp
type level
type access
val trans_exp: unit -> exp
val outermost: level
val newLevel: parent:level -> name:Temp.label -> formals:bool list -> level
val formals: level -> access list
val allocLocal: level:level -> escapes:bool -> access
end
module F : functor(Frame: Frame.FRAME) -> TRANSLATE with module Frame = Frame
and in translate.ml I implement as belows;
module type TRANSLATE = sig
module Frame: Frame.FRAME
module Temp = Frame.Temp
type exp
type level
type access
val trans_exp: unit -> exp
val outermost: level
val newLevel: parent:level -> name:Temp.label -> formals:bool list -> level
val formals: level -> access list
val allocLocal: level:level -> escapes:bool -> access
end
module F = functor(Frame : Frame.FRAME) -> struct
module Frame = Frame
module Temp = Frame.Temp
type exp = unit
type level = Outermost
| Level of Frame.frame * level * unit ref
type access = level * Frame.access
let trans_exp() = ()
let outermost = Outermost
let newLevel ~parent ~name ~formals =
let formals = true :: formals in
let frame = Frame.newFrame ~name ~formals in
Level(frame, parent, ref())
let formals lvl =
match lvl with
| Outermost -> assert false
| Level(frame, _, _) -> Frame.formals frame |> List.tl_exn |> List.map ~f:(fun access -> (lvl, access))
let allocLocal ~level ~escapes =
match level with
| Level(frame, _, _) -> (level, Frame.allocLocal frame escapes)
| Outermost -> assert false
end
in visual studio code the OCaml platform inference the F’s type as below;
functor (Frame : Frame/3.FRAME) ->
sig
module Frame :
sig
type frame = Frame.frame
type access = Frame.access
type label = Frame.label
module Temp = Chap6.Temp
val newFrame : name:label -> formals:bool list -> frame
val name : frame -> label
val formals : frame -> access list
val allocLocal : frame -> bool -> access
end
module Temp = Frame.Temp
type exp = unit
type level = Outermost | Level of Frame/2.frame * level * exp ref
type access = level * Frame/2.access
val trans_exp : exp -> exp
val outermost : level
val newLevel :
parent:level -> name:Frame/2.label -> formals:bool list -> level
val formals : level -> (level * Frame/2.access) list
val allocLocal : level:level -> escapes:bool -> level * Frame/2.access
end
I don’t know why the Frame’s type is Frame/3.FRAME.
And there is some compiling errors
Error: The implementation translate.pp.ml
does not match the interface .chap6.objs/byte/chap6__Translate.cmi:
...
At position module F(Frame) : <here>
Values do not match:
val newLevel :
parent:level -> name:Frame.label -> formals:bool list -> level
is not included in
val newLevel :
parent:level -> name:Temp.label -> formals:bool list -> level
File "translate.mli", line 10, characters 4-79: Expected declaration
File "translate.ml", line 35, characters 4-12: Actual declaration