<commit_before>type meta = int

let fresh_meta : unit -> meta =
  let counter = ref 0 in
  fun () ->
    let m = !counter in
    incr counter;
    m

module MetaOrd = struct
  type t = meta

  let compare = compare
end

type ty =
  | Jdg
  | String
  | Meta of meta
  | Tuple of ty list
  | Arrow of ty * ty
  | Handler of ty * ty
  | App of Name.ident * Syntax.level * ty list
  | Ref of ty

let fresh_type () = Meta (fresh_meta ())

(** The metavariables are generalised in the following values. *)
type 'a forall = meta list * 'a

type ty_schema = ty forall

type constructor = Name.constructor * ty list

type ty_def =
  | Alias of ty forall
  | Sum of constructor list forall

(** Make a schema from a type without generalizing anything. *)
let ungeneralized_schema (t : ty) : ty_schema = [], t

type error =
  | InvalidApplication of ty * ty * ty
  | TypeMismatch of ty * ty
  | UnsolvedApp of ty * ty * ty
  | HandlerExpected of ty
  | RefExpected of ty
  | UnknownExternal of string

exception Error of error Location.located

let error ~loc err = Pervasives.raise (Error (Location.locate err loc))

type print_env = (meta * string) list ref

let fresh_penv () = ref []

let print_meta ~penv (m : meta) ppf =
  let s =
    try List.assoc m !penv
    with Not_found ->
      let l = List.length !penv in
      let s = Name.greek l in
      penv := (m, s) :: !penv;
      s
  in
  Format.fprintf ppf "%s" s

let rec print_ty ~penv ?max_level t ppf =
  match t with

  | Jdg -> Format.fprintf ppf "Judgement"

  | String -> Format.fprintf ppf "string"

  | Meta m -> print_meta ~penv m ppf

  | Tuple ts -> Print.print ?max_level ppf "%t"
                            (Print.sequence (print_ty ~penv ~max_level:Level.ml_prod_arg) " *" ts)

  | Arrow (t1, t2) ->
     Print.print ?max_level ~at_level:(Level.ml_arr) ppf "%t@ %s@ %t"
                 (print_ty ~penv ~max_level:(Level.ml_arr_left) t1)
                 (Print.char_arrow ())
                 (print_ty ~penv ~max_level:(Level.ml_arr_right) t2)

  | Handler (t1, t2) ->
     Print.print ?max_level ~at_level:(Level.ml_handler) ppf "%t@ %s@ %t"
                 (print_ty ~penv ~max_level:(Level.ml_handler_left) t1)
                 (Print.char_darrow ())
                 (print_ty ~penv ~max_level:(Level.ml_handler_right) t2)

  | App (x, _, []) ->
     Format.fprintf ppf "%t" (Name.print_ident x)

  | App (x, _, ts) -><commit_msg>Fix printing of the unit type.<commit_after>type meta = int

let fresh_meta : unit -> meta =
  let counter = ref 0 in
  fun () ->
    let m = !counter in
    incr counter;
    m

module MetaOrd = struct
  type t = meta

  let compare = compare
end

type ty =
  | Jdg
  | String
  | Meta of meta
  | Tuple of ty list
  | Arrow of ty * ty
  | Handler of ty * ty
  | App of Name.ident * Syntax.level * ty list
  | Ref of ty

let fresh_type () = Meta (fresh_meta ())

(** The metavariables are generalised in the following values. *)
type 'a forall = meta list * 'a

type ty_schema = ty forall

type constructor = Name.constructor * ty list

type ty_def =
  | Alias of ty forall
  | Sum of constructor list forall

(** Make a schema from a type without generalizing anything. *)
let ungeneralized_schema (t : ty) : ty_schema = [], t

type error =
  | InvalidApplication of ty * ty * ty
  | TypeMismatch of ty * ty
  | UnsolvedApp of ty * ty * ty
  | HandlerExpected of ty
  | RefExpected of ty
  | UnknownExternal of string

exception Error of error Location.located

let error ~loc err = Pervasives.raise (Error (Location.locate err loc))

type print_env = (meta * string) list ref

let fresh_penv () = ref []

let print_meta ~penv (m : meta) ppf =
  let s =
    try List.assoc m !penv
    with Not_found ->
      let l = List.length !penv in
      let s = Name.greek l in
      penv := (m, s) :: !penv;
      s
  in
  Format.fprintf ppf "%s" s

let rec print_ty ~penv ?max_level t ppf =
  match t with

  | Jdg -> Format.fprintf ppf "judgment"

  | String -> Format.fprintf ppf "string"

  | Meta m -> print_meta ~penv m ppf

  | Tuple [] -> Format.fprintf ppf "unit"

  | Tuple ts -> Print.print ?max_level ppf "%t"
                            (Print.sequence (print_ty ~penv ~max_level:Level.ml_prod_arg) " *" ts)

  | Arrow (t1, t2) ->
     Print.print ?max_level ~at_level:(Level.ml_arr) ppf "%t@ %s@ %t"
                 (print_ty ~penv ~max_level:(Level.ml_arr_left) t1)
                 (Print.char_arrow ())
                 (print_ty ~penv ~max_level:(Level.ml_arr_right) t2)

  | Handler (t1, t2) ->
     Print.print ?max_level ~at_level:(Level.ml_handler) ppf "%t@ %s@ %t"
                 (print_ty ~penv ~max_level:(Level.ml_handler_left) t1)
                 (Print.char_darrow ())
                 (print_ty ~penv ~max_level:(Level.ml_handler_right) t2)

  | App (x, _, []) ->
     Format.fprintf ppf "%t" (Name.print_ident x)

  | App (x, _, ts) ->
{'fraction_non_alphanumeric': 0.1144912641315519, 'fraction_numerical': 0.0036998972250770813, 'mean_word_length': 2.4982027318475915, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 26, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6305794', 'n_tokens_mistral': 1763, 'n_tokens_neox': 1708, 'n_words': 561}