Created
July 20, 2019 22:44
-
-
Save calebh/23a4cde754d185e4e611960fd0e64c16 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let rec tysubst theta t = | |
match t with | |
| TVarExpr u -> | |
match Map.tryFind u theta with | |
| Some t' -> t' | |
| None -> t | |
| TApExpr (l, r) -> | |
TApExpr (tysubst theta l, tysubst theta r) | |
| _ -> | |
t | |
let n = ref 1 | |
let freshpolytyvar kind = | |
let ret = TyVar (sprintf "t%i" !n, kind) | |
n := !n + 1 | |
ret | |
let freshtyvar _ = | |
freshpolytyvar Star | |
let instantiate (Forall (formals, tau)) actuals = | |
tysubst (Map.ofList (List.zip formals actuals)) tau | |
let rec freevars t = | |
match t with | |
| TVarExpr u -> Set.singleton u | |
| TApExpr (l, r) -> Set.union (freevars l) (freevars r) | |
| TConExpr _ -> Set.empty | |
let generalize skipTyVars tau = | |
let ts = freevars tau | |
Forall (Set.difference ts skipTyVars |> List.ofSeq, tau) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment