Commit 439f1069 by Mark Cohen

compiler: correct freeVars to not return duplicates

parent e4e38e72
Showing with 12 additions and 6 deletions
......@@ -13,13 +13,19 @@ end = struct
type tyScheme = {sigmas: string list, rhos: (string * Ty.ty) list, tau: Ty.ty}
local open Ty in
fun freeVars (Unit | Bool | Int) = []
| freeVars (List ty) = freeVars ty
| freeVars (Pair (ty1, ty2)) = (freeVars ty1) @ (freeVars ty2)
| freeVars (Option ty) = freeVars ty
| freeVars (Fun (ty1, ty2)) = (freeVars ty1) @ (freeVars ty2)
| freeVars (TyVar a) = [a]
fun freeVars' (Unit | Bool | Int) = []
| freeVars' (List ty) = freeVars' ty
| freeVars' (Pair (ty1, ty2)) = (freeVars' ty1) @ (freeVars' ty2)
| freeVars' (Option ty) = freeVars' ty
| freeVars' (Fun (ty1, ty2)) = (freeVars' ty1) @ (freeVars' ty2)
| freeVars' (TyVar a) = [a]
end
fun dedup [] = []
| dedup (x :: xs) =
if List.exists (fn x' => x = x') xs
then dedup xs
else x :: dedup xs
val freeVars = dedup o freeVars'
fun generalize ty =
{sigmas = freeVars ty, rhos = [], tau = ty}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment