diff options
author | Nadrieril | 2019-08-20 23:02:56 +0200 |
---|---|---|
committer | Nadrieril | 2019-08-20 23:02:56 +0200 |
commit | 8c1ffc5b68489be4694fff922ca48afeb0d45fc4 (patch) | |
tree | eecdc34e8768105bf67b2a3cb734b3694dbfccac /dhall/src | |
parent | 8e68396e9fe3751bcf8bcfd68301ca7fea836787 (diff) |
Move type construction fns from serde_dhall to dhall
Diffstat (limited to '')
-rw-r--r-- | dhall/src/phase/mod.rs | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/dhall/src/phase/mod.rs b/dhall/src/phase/mod.rs index 1f80791..b5b7b64 100644 --- a/dhall/src/phase/mod.rs +++ b/dhall/src/phase/mod.rs @@ -1,7 +1,7 @@ use std::fmt::Display; use std::path::Path; -use dhall_syntax::{Const, SubExpr}; +use dhall_syntax::{Builtin, Const, SubExpr}; use crate::core::value::Value; use crate::core::valuef::ValueF; @@ -123,6 +123,39 @@ impl Typed { pub(crate) fn get_type(&self) -> Result<Typed, TypeError> { Ok(self.0.get_type()?.into_typed()) } + + pub fn make_builtin_type(b: Builtin) -> Self { + Typed::from_value(Value::from_builtin(b)) + } + pub fn make_optional_type(t: Typed) -> Self { + Typed::from_value( + Value::from_builtin(Builtin::Optional).app(t.to_value()), + ) + } + pub fn make_list_type(t: Typed) -> Self { + Typed::from_value(Value::from_builtin(Builtin::List).app(t.to_value())) + } + pub fn make_record_type( + kts: impl Iterator<Item = (String, Typed)>, + ) -> Self { + Typed::from_valuef_and_type( + ValueF::RecordType( + kts.map(|(k, t)| (k.into(), t.into_value())).collect(), + ), + Typed::const_type(), + ) + } + pub fn make_union_type( + kts: impl Iterator<Item = (String, Option<Typed>)>, + ) -> Self { + Typed::from_valuef_and_type( + ValueF::UnionType( + kts.map(|(k, t)| (k.into(), t.map(|t| t.into_value()))) + .collect(), + ), + Typed::const_type(), + ) + } } impl Normalized { |