Skip to content

Commit

Permalink
Updates to TYp.re, removed old comment about to_typ
Browse files Browse the repository at this point in the history
  • Loading branch information
isdiemer committed Feb 8, 2025
1 parent 0b64114 commit a834370
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/haz3lcore/lang/term/Typ.re
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type cls =
| Var
| Constructor
| Parens
| ParamAp
| Ap
| Rec
| Forall;
Expand Down Expand Up @@ -82,6 +83,7 @@ let cls_of_term: term => cls =
| Ap(_) => Ap
| Sum(_) => Sum
| Rec(_) => Rec
| ParamAp(_) => ParamAp
| Forall(_) => Forall;

let show_cls: cls => string =
Expand All @@ -102,6 +104,7 @@ let show_cls: cls => string =
| Prod => "Product type"
| Sum => "Sum type"
| Parens => "Parenthesized type"
| ParamAp => "Parameterized type"
| Ap => "Constructor application"
| Rec => "Recursive type"
| Forall => "Forall type";
Expand All @@ -121,6 +124,7 @@ let rec is_arrow = (typ: t) => {
| Ap(_)
| Sum(_)
| Forall(_)
| ParamAp(_)
| Rec(_) => false
};
};
Expand All @@ -140,11 +144,11 @@ let rec is_forall = (typ: t) => {
| Var(_)
| Ap(_)
| Sum(_)
| ParamAp(_)
| Rec(_) => false
};
};

/* Functions below this point assume that types have been through the to_typ function above */

[@deriving (show({with_path: false}), sexp, yojson)]
type source = {
Expand Down Expand Up @@ -180,6 +184,7 @@ let rec free_vars = (~bound=[], ty: t): list(Var.t) =>
| Float
| Bool
| String => []
| ParamAp(t1,t2) => free_vars(~bound,t1) @ free_vars(~bound, t2)
| Ap(t1, t2) => free_vars(~bound, t1) @ free_vars(~bound, t2)
| Var(v) => List.mem(v, bound) ? [] : [v]
| Parens(ty) => free_vars(~bound, ty)
Expand Down Expand Up @@ -506,6 +511,7 @@ let rec needs_parens = (ty: t): bool =>
| Rec(_, _)
| Forall(_, _) => true
| List(_) => false /* is already wrapped in [] */
| ParamAp(_) => false
| Arrow(_, _) => true
| Prod(_)
| Sum(_) => true /* disambiguate between (A + B) -> C and A + (B -> C) */
Expand All @@ -529,6 +535,7 @@ let rec pretty_print = (ty: t): string =>
switch (term_of(ty)) {
| Parens(ty) => pretty_print(ty)
| Ap(_)
| ParamAp(_) /* Temporary */
| Unknown(_) => "?"
| Int => "Int"
| Float => "Float"
Expand Down

0 comments on commit a834370

Please sign in to comment.