From 695e733584cb823844b3e18949093dae35758063 Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 3 Mar 2018 11:52:07 -0800 Subject: [PATCH] Sum types in type schema --- src/schala_lang/typechecking.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/schala_lang/typechecking.rs b/src/schala_lang/typechecking.rs index a791fcc..df78034 100644 --- a/src/schala_lang/typechecking.rs +++ b/src/schala_lang/typechecking.rs @@ -4,6 +4,8 @@ use std::char; use std::fmt; use std::fmt::Write; +use itertools::Itertools; + use schala_lang::parsing; pub struct TypeContext { @@ -14,6 +16,7 @@ pub struct TypeContext { #[derive(Debug, PartialEq, Clone)] pub enum Type { Const(TConst), + Sum(Vec), Func(Box, Box), UVar(String), EVar(u64), @@ -25,6 +28,16 @@ impl fmt::Display for Type { use self::Type::*; match self { &Const(ref c) => write!(f, "{:?}", c), + &Sum(ref types) => { + write!(f, "(")?; + for item in types.iter().map(|ty| Some(ty)).intersperse(None) { + match item { + Some(ty) => write!(f, "{}", ty)?, + None => write!(f, ",")?, + }; + } + write!(f, ")") + }, &Func(ref a, ref b) => write!(f, "{} -> {}", a, b), &UVar(ref s) => write!(f, "{}_u", s), &EVar(ref n) => write!(f, "{}_e", n),