Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module type Symbol = sig
- type t
- val symbol : string -> t
- val name : t -> string
- type 'a table
- val empty : 'a table
- val enter : 'a table -> t -> 'a -> 'a table
- val look : 'a table -> t -> 'a option
- end
- module Symbol : Symbol = struct
- open Core.Std
- type t = int
- let nextsym = ref 0
- let symtbl = String.Table.create ()
- let inv_symtbl = Int.Table.create ()
- let symbol s = match Hashtbl.find symtbl s with
- | Some x -> x
- | None ->
- let sym = !nextsym
- in (nextsym := sym + 1;
- Hashtbl.set symtbl ~key:s ~data:sym;
- Hashtbl.set inv_symtbl ~key:sym ~data:s;
- sym)
- let name sym = match Hashtbl.find inv_symtbl sym with
- | Some x -> x
- | None -> ""
- type 'a table = 'a Int.Table.t
- let empty : 'a table = Int.Table.create () ~size: 4
- let enter tbl s data = Hashtbl.set tbl ~key:s ~data
- let look tbl s = Hashtbl.find tbl s
- end
- (*
- Error: Signature mismatch:
- module type Symbol =
- ...
- sig
- Values do not match:
- type t
- val empty : '_a table
- val symbol : string -> t
- is not included in
- val name : t -> string
- val empty : 'a table
- type 'a table
- val empty : 'a table
- val enter : 'a table -> t -> 'a -> 'a table
- val look : 'a table -> t -> 'a option
- end
- *)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement