Function gluon_check::typecheck::unroll_typ [] [src]

pub fn unroll_typ(typ: &Type<Symbol>) -> Option<ArcType>

Removes layers of Type::App and Type::Record by packing them into a single Type::App or Type::Record

Example:

#[macro_use]
extern crate collect_mac;
extern crate gluon_base;
extern crate gluon_check;

use gluon_base::types::{Type, ArcType, BuiltinType};
use gluon_check::typecheck::unroll_typ;

let i: ArcType = Type::int();
let s: ArcType = Type::string();
assert_eq!(unroll_typ(&*Type::app(Type::app(i.clone(), collect![s.clone()]), collect![i.clone()])),
           Some(Type::app(i.clone(), collect![s.clone(), i.clone()])));
assert_eq!(unroll_typ(&*Type::app(Type::app(i.clone(), collect![i.clone()]), collect![s.clone()])),
           Some(Type::app(i.clone(), collect![i.clone(), s.clone()])));
let f: ArcType = Type::builtin(BuiltinType::Function);
assert_eq!(unroll_typ(&*Type::app(Type::app(f.clone(), collect![i.clone()]), collect![s.clone()])),
           Some(Type::function(collect![i.clone()], s.clone())));