Raw text file


(* Section 2 *)

(* Identity of an inductive : its name and and an integer indicating
   the version of the constructor *)
type inductive_id = {
  name : string;
  index: int;
}


(* Typing environments, as association list mapping a name to
   the current version of the type constructor *)
type env = (string * inductive_id) list

let resolve_inductive (env : env) s = List.assoc s env


(* Implementation using standard inductive types *)
module IND = struct

type typeconstr = Int | Float | Arrow | Uple of int | Inductive of inductive_id
type parsing_typeconstr = PInt | PFloat | PArrow | PUple of int |
                          PInductive of string

let resolve_typeconstr env = function
| PInt -> Int | PFloat -> Float | PArrow -> Arrow | PUple n -> Uple n
| PInductive s -> Inductive (resolve_inductive env s)

end



(* Implementation using polymorphic variants *)
module PV = struct

type common_typeconstr = [ `Int | `Float | `Arrow | `Uple of int ]

type typeconstr =  [ common_typeconstr | `Inductive of inductive_id ]
type parsing_typeconstr = [ common_typeconstr | `Inductive of string ]


(* Pretty printer for constructors common to both definitions *)
let print_typeconstr_common : common_typeconstr -> unit = function
  | `Int -> print_string "int"
  | `Float -> print_string "float"
  | `Arrow -> print_string "->"
  | `Uple n -> print_string "(" ; print_int n ; print_string ")"

(* Pretty printer for parsing_typeconstr, using dispatch *)
let print_typeconstr_parsing : parsing_typeconstr -> unit = function
  | #common_typeconstr as x -> print_typeconstr_common x
  | `Inductive s -> print_string s


let resolve_typeconstr env : parsing_typeconstr -> typeconstr = function
  | #common_typeconstr as x -> x
  | `Inductive s -> `Inductive (resolve_inductive env s)

end

This document was generated using caml2html