Sum types in type schema
This commit is contained in:
parent
a300f78e19
commit
08e10739e5
@ -4,6 +4,8 @@ use std::char;
|
|||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::fmt::Write;
|
use std::fmt::Write;
|
||||||
|
|
||||||
|
use itertools::Itertools;
|
||||||
|
|
||||||
use schala_lang::parsing;
|
use schala_lang::parsing;
|
||||||
|
|
||||||
pub struct TypeContext {
|
pub struct TypeContext {
|
||||||
@ -14,6 +16,7 @@ pub struct TypeContext {
|
|||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
pub enum Type {
|
pub enum Type {
|
||||||
Const(TConst),
|
Const(TConst),
|
||||||
|
Sum(Vec<Type>),
|
||||||
Func(Box<Type>, Box<Type>),
|
Func(Box<Type>, Box<Type>),
|
||||||
UVar(String),
|
UVar(String),
|
||||||
EVar(u64),
|
EVar(u64),
|
||||||
@ -25,6 +28,16 @@ impl fmt::Display for Type {
|
|||||||
use self::Type::*;
|
use self::Type::*;
|
||||||
match self {
|
match self {
|
||||||
&Const(ref c) => write!(f, "{:?}", c),
|
&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),
|
&Func(ref a, ref b) => write!(f, "{} -> {}", a, b),
|
||||||
&UVar(ref s) => write!(f, "{}_u", s),
|
&UVar(ref s) => write!(f, "{}_u", s),
|
||||||
&EVar(ref n) => write!(f, "{}_e", n),
|
&EVar(ref n) => write!(f, "{}_e", n),
|
||||||
|
Loading…
Reference in New Issue
Block a user