Kind/book
Victor Taelin 29d8338f4a unification fine polishments - see notes
1. Previously, the following term wouldn't type-check:

      match x = term {
        true: ct
        false: cf
      }

When `term` isn't a variable.

The reason is that the `match` syntax was desugared to:

    (~term _ ct cf)

Which, in general, results in the following check:

    true : ∀(P: Bool -> *) ∀(t: P true) ∀(f: P false) (P term)

    check _  :: Bool -> *
    check ct :: (_ true)
    check cf :: (_ false)
    check () :: (_ term)

    unify (_ term) == (P term)

This should generate the solution:

    _ = λx(P x)

But, when `term` isn't a variable (it could be a function call, or a ref, for
example), this fails to satisfy the pattern unification criteria. To fix that,
we just use a `let` to always create a variable before unifying, so that the
`match` syntax is desugared to:

      let x = term
      (~x _ ct cf)

Which solves the issue.

2. Previously, the following term wouldn't type-check:

    equal (a: Nat) (b: Nat) : Bool =
      match a with (b: Nat) {
        succ: match b {
          succ: (equal a.pred b.pred)
          zero: false
        }
        zero: match b {
          succ: false
          zero: true
        }
      }

After inspecting the type-checker output, I noticed the reason is due to how the
outer hole interacts with the inner hole. Specifically, after some computations
we eventually get to the following unification problem:

    unify _2 == (_3 b)

Here, there are two ways to solve this:

    _2 = (_3 b)

    or

    _3 = λx (_2)

Initially, it seems like both solutions are equivalent. Yet, by choosing the
first, we, later on, face the following problem:

    - (_3 (succ x))
    - Bool

Which violates the pattern unification requisites (for the same reason: `succ`
is a constructor, rather than a variable). A way to solve this problem would be
to simply invert the order, and use `_3 = λx (_2)` instead (done in the last
commit). That way, we'd have `(_3 (succ x))` reduce to just `_2`, which would
solve `_2 = Bool` and type-check fine. This is a quickfix though. I wonder if
there is a more principled approach that would let us avoid `(succ x)` to be
there at all.

Debug log: https://gist.github.com/VictorTaelin/6dd1a7167d5b7c8d5626c0f5b88c75a0
2024-03-18 16:59:21 -03:00
..
BBT diff savida 2024-03-15 22:07:01 -03:00
Bool unification fine polishments - see notes 2024-03-18 16:59:21 -03:00
Char diff savida 2024-03-15 22:07:01 -03:00
Cmp diff savida 2024-03-15 22:07:01 -03:00
Empty diff savida 2024-03-15 22:07:01 -03:00
Equal diff savida 2024-03-15 22:07:01 -03:00
HVM diff savida 2024-03-15 22:07:01 -03:00
IO diff savida 2024-03-15 22:07:01 -03:00
Kind diff savida 2024-03-15 22:07:01 -03:00
List unification fine polishments - see notes 2024-03-18 16:59:21 -03:00
Maybe diff savida 2024-03-15 22:07:01 -03:00
Monad diff savida 2024-03-15 22:07:01 -03:00
Nat unification fine polishments - see notes 2024-03-18 16:59:21 -03:00
Pair diff savida 2024-03-15 22:07:01 -03:00
Parser diff savida 2024-03-15 22:07:01 -03:00
QBool diff savida 2024-03-15 22:07:01 -03:00
QBool2 diff savida 2024-03-15 22:07:01 -03:00
Sigma diff savida 2024-03-15 22:07:01 -03:00
String diff savida 2024-03-15 22:07:01 -03:00
The diff savida 2024-03-15 22:07:01 -03:00
Tree first kind2-hvm2 program run! sum-tree via fold 2024-03-15 23:06:44 -03:00
U60 unification fine polishments - see notes 2024-03-18 16:59:21 -03:00
Unit diff savida 2024-03-15 22:07:01 -03:00
Vector diff savida 2024-03-15 22:07:01 -03:00
_check_all.sh auto formatter 2024-03-01 20:40:31 -03:00
_err.txt U60 syntax without hashtag; numeric match now called switch 2024-03-14 13:35:03 -03:00
_main first kind2-hvm2 program run! sum-tree via fold 2024-03-15 23:06:44 -03:00
_main.hvm2 first kind2-hvm2 program run! sum-tree via fold 2024-03-15 23:06:44 -03:00
_main.hvmc first kind2-hvm2 program run! sum-tree via fold 2024-03-15 23:06:44 -03:00
_main.js first kind2-hvm2 program run! sum-tree via fold 2024-03-15 23:06:44 -03:00
_main.kind2 first kind2-hvm2 program run! sum-tree via fold 2024-03-15 23:06:44 -03:00
_OBLITERATE.kind2 fix obliterate 2024-03-01 12:21:43 -03:00
_tmp.hvm2 implicits args and stuff 2024-03-15 18:51:25 -03:00
_tmp.kind2 implicits args and stuff 2024-03-15 18:51:25 -03:00
BBT.kind2 U60 syntax without hashtag; numeric match now called switch 2024-03-14 13:35:03 -03:00
Bool.kind2 use-declarations with shadowing 2024-03-12 18:01:12 -03:00
Char.kind2 U60 syntax without hashtag; numeric match now called switch 2024-03-14 13:35:03 -03:00
Cmp.kind2 diff savida 2024-03-15 22:07:01 -03:00
Empty.kind2 diff savida 2024-03-15 22:07:01 -03:00
Equal.kind2 diff savida 2024-03-15 22:07:01 -03:00
IO.kind2 U60 syntax without hashtag; numeric match now called switch 2024-03-14 13:35:03 -03:00
Kind.kind2 use-notation 2024-03-08 17:39:37 -03:00
List.kind2 pattern-match syntax 2024-03-12 13:44:49 -03:00
Maybe.kind2 diff savida 2024-03-15 22:07:01 -03:00
Monad.kind2 diff savida 2024-03-15 22:07:01 -03:00
Nat.kind2 ADT syntax continuation 2024-03-12 11:55:09 -03:00
Pair.kind2 diff savida 2024-03-15 22:07:01 -03:00
Parser.kind2 auto formatter 2024-03-01 20:40:31 -03:00
QBool2.kind2 Fix some syntaxes uses of switch +: to _: 2024-03-14 17:07:40 -03:00
QBool.kind2 Fix some syntaxes uses of switch +: to _: 2024-03-14 17:07:40 -03:00
QUnit.kind2 Fix some syntaxes uses of switch +: to _: 2024-03-14 17:07:40 -03:00
script.js diff savida 2024-03-15 22:07:01 -03:00
Sigma.kind2 list/nat syntax sugars, reorganizations 2024-03-09 17:59:39 -03:00
String.kind2 diff savida 2024-03-15 22:07:01 -03:00
test0.kind2 working hs 2024-03-06 11:35:17 -03:00
test1.kind2 U60 syntax without hashtag; numeric match now called switch 2024-03-14 13:35:03 -03:00
test2.kind2 U60 syntax without hashtag; numeric match now called switch 2024-03-14 13:35:03 -03:00
test3.kind2 U60 syntax without hashtag; numeric match now called switch 2024-03-14 13:35:03 -03:00
test4.kind2 auto formatter 2024-03-01 20:40:31 -03:00
test5.kind2 auto formatter 2024-03-01 20:40:31 -03:00
test6.kind2 auto formatter 2024-03-01 20:40:31 -03:00
test7.kind2 auto formatter 2024-03-01 20:40:31 -03:00
test8.kind2 U60 syntax without hashtag; numeric match now called switch 2024-03-14 13:35:03 -03:00
test9.kind2 U60 syntax without hashtag; numeric match now called switch 2024-03-14 13:35:03 -03:00
test10.kind2 use-notation 2024-03-08 17:39:37 -03:00
test11.kind2 U60 syntax without hashtag; numeric match now called switch 2024-03-14 13:35:03 -03:00
testBBT.kind2 auto formatter 2024-03-01 20:40:31 -03:00
The.kind2 diff savida 2024-03-15 22:07:01 -03:00
Tree.kind2 first kind2-hvm2 program run! sum-tree via fold 2024-03-15 23:06:44 -03:00
Unit.kind2 diff savida 2024-03-15 22:07:01 -03:00
Vector.kind2 diff savida 2024-03-15 22:07:01 -03:00