Skip to content

Commit

Permalink
[ check ] Fix type-checking bug, add more example
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Sep 5, 2019
1 parent eb1b3f8 commit 7f8c065
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# 0.1.6

+ Integrate `minitt-util` for CLI
+ Fix type-checking bug
+ Fix reduction bug

# 0.1.5

Expand Down
20 changes: 20 additions & 0 deletions samples/row-polymorphism/extensible-pattern-match.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Parse successful.
sign: set1
body: Rec {}
sign: set1
body: Sum {}
sign: Rec {}
body: {||}
sign: set1
body: Sum {False: Rec {}, True: Rec {}}
sign: Sum {False: Rec {}, True: Rec {}}
body: (@True {||})
sign: Sum {False: Rec {}, True: Rec {}}
body: (@False {||})
sign: ((Sum {False: Rec {}} -> Sum {False: Rec {}, True: Rec {}}) -> (Sum {False: Rec {}, True: Rec {}} -> Sum {False: Rec {}, True: Rec {}}))
body: (\ (cases {{ True: \ (\ (@False {||})); } or [0]))
sign: ((Sum {} -> Sum {False: Rec {}, True: Rec {}}) -> (Sum {False: Rec {}} -> Sum {False: Rec {}, True: Rec {}}))
body: (\ (cases {{ False: \ (\ (@True {||})); } or [0]))
sign: (Sum {False: Rec {}, True: Rec {}} -> Sum {False: Rec {}, True: Rec {}})
body: (\ False => (\ (@True {||})); True => (\ (@False {||})); )
Checkmate, dram!
30 changes: 30 additions & 0 deletions samples/row-polymorphism/extensible-pattern-match.voile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// Created by Dependently-Typed Lambda Calculus on 2019-08-29
// simple-pattern-match
// Author: ice10
//

let Unit = Rec {};
let Bottom = Sum {};

val unit : Unit;
let unit = {| |};

let Bool = Sum { True: Unit; False: Unit; };

val true : Bool;
let true = @True unit;

val false : Bool;
let false = @False unit;

val notTrue : (Sum { False: Unit; } -> Bool)
-> Bool -> Bool;
let notTrue = \f. case True u: false or f;

val notFalse : (Bottom -> Bool)
-> Sum { False: Unit; } -> Bool;
let notFalse = \f. case False u: true or f;

val not : Bool -> Bool;
let not = notTrue (notFalse whatever);
2 changes: 1 addition & 1 deletion src/check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ fn check(mut tcs: TCS, expr: &Abs, expected_type: &Val) -> ValTCM {
Val::RowPoly(Variant, variants) if variants.is_empty() => {
Ok((Val::Lam(Closure::default()).into_info(*info), tcs))
}
ty => Err(TCE::NotRowType(Variant, (*info).clone(), ty.clone())),
ty => Err(TCE::NotEmpty(info.clone(), ty.clone())),
},
// How about when `Dt` is `Plicit::Im`?
(CaseOr(label, binding, uid, body, or), Val::Dt(Pi, Plicit::Ex, param_ty, ret_ty)) => {
Expand Down
6 changes: 6 additions & 0 deletions src/check/monad/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub enum TCE {
NotTypeAbs(Loc, Abs),
NotTypeVal(Loc, Val),
NotRowType(VarRec, Loc, Val),
NotEmpty(Loc, Val),
NotRecVal(Loc, Val),
NotUniverseVal(Loc, Val),

Expand Down Expand Up @@ -107,6 +108,11 @@ impl Display for TCE {
"Expected a variant type expression, got: `{}` at {}.",
val, id
),
TCE::NotEmpty(id, val) => write!(
f,
"Expected an empty type expression, got: `{}` at {}.",
val, id
),
TCE::MissingVariant(VarRec::Variant, variant) => {
write!(f, "Missing variant `{}`.", variant)
}
Expand Down

0 comments on commit 7f8c065

Please sign in to comment.