Skip to content

Instantly share code, notes, and snippets.

@7h3kk1d
Created February 4, 2025 15:09
Show Gist options
  • Save 7h3kk1d/60d9bfc4ab73a226b22f088a12e1a4ef to your computer and use it in GitHub Desktop.
Save 7h3kk1d/60d9bfc4ab73a226b22f088a12e1a4ef to your computer and use it in GitHub Desktop.
module type Grammar = {
type typ;
type exp;
};
module Typ = (G: Grammar) => {
type t =
| Int
| Float
| Bool
| String
| Var(string)
| List(G.typ)
| Prod(list(G.typ));
};
module Exp = (G: Grammar) => {
type t =
| Undefined
| Bool(bool)
| Int(int)
| Float(float)
| String(string)
| ListLit(list(G.exp))
| Cast(G.exp, G.typ, G.typ);
};
module rec Grammar: {
type typ = Typ(Grammar).t;
type exp = Exp(Grammar).t;
} = {
type typ = Typ(Grammar).t;
type exp = Exp(Grammar).t;
};
module rec TaggedGrammar: {
type typ = IdTagged.t(Typ(TaggedGrammar).t);
type exp = IdTagged.t(Exp(TaggedGrammar).t);
} = {
type typ = IdTagged.t(Typ(TaggedGrammar).t);
type exp = IdTagged.t(Exp(TaggedGrammar).t);
};
module rec StaticInformationGrammar: {
type typ = Typ(StaticInformationGrammar).t;
type exp = (Exp(StaticInformationGrammar).t, Info.status_exp);
} = {
type typ = Typ(StaticInformationGrammar).t;
type exp = (Exp(StaticInformationGrammar).t, Info.status_exp);
};
let plain_expression: Grammar.exp =
Cast(
ListLit([Int(7), Int(3), Bool(true)]),
Int,
Prod([Int, Bool, String]),
);
module IdE = Exp(TaggedGrammar);
module IdT = Typ(TaggedGrammar);
let id_tagged_expression: TaggedGrammar.exp =
IdTagged.fresh(
IdE.Cast(
IdE.(
ListLit([
Int(7) |> IdTagged.fresh,
Int(3) |> IdTagged.fresh,
Bool(true) |> IdTagged.fresh,
])
)
|> IdTagged.fresh,
IdT.Int |> IdTagged.fresh,
IdT.(
Prod([
Int |> IdTagged.fresh,
Bool |> IdTagged.fresh,
String |> IdTagged.fresh,
])
)
|> IdTagged.fresh,
),
);
module SE = Exp(StaticInformationGrammar);
module ST = Typ(StaticInformationGrammar);
let statically_determined_expression: StaticInformationGrammar.exp = (
SE.Int(7),
InHole(Common(NoType(BadToken("bad token")))),
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment