Skip to content

-o/--verdict leave out a def that copies a hypothesis of computed type after a match refined it ("a λ that uses a variable twice") (2.0.35) #1349

Closed

Description

@jeromelaurens

What you did

Bend 2.0.35 (79df8d9c), Bun 1.3.14, macOS arm64, kernel built from
bend2/bendtt.lean (digest e15042434e73aab0).

import Base

type Spine is Data:
  SpineEnd{}
  SpineCon{head: Nat, tail: Spine}

def AtEnd(rest: Spine, b: Nat) -> Type:
  match rest:
    case SpineEnd{}: {Nat.is_le(b, 7n) == True{} : Bool}
    case SpineCon{x, r}: Unit

def PairAtEnd(rest: Spine, +b: Nat) -> Type:
  match rest:
    case SpineEnd{}:
      {Nat.is_le(b, 7n) == True{} : Bool} & {Nat.is_le(b, 7n) == True{} : Bool}
    case SpineCon{x, r}: Unit

def duplicate(rest: Spine, +b: Nat, proof: AtEnd(rest, b)) -> PairAtEnd(rest, b):
  match rest:
    case SpineEnd{}:
      +copy = {proof : {Nat.is_le(b, 7n) == True{} : Bool}}
      (copy, copy)
    case SpineCon{x, r}: Unit{}
$ bend copy.bend
ALL PROOFS CHECK
$ bend copy.bend -o copy.bendtt
BendTT: out of scope, so not in copy.bendtt:
- duplicate: a λ that uses a variable twice, of a type whose fields are not Data (a ~ argument)
$ bend copy.bend --verdict
SOME PROOFS FAIL
Sorry - this is a mismatch between the TypeScript implementation, and the formalized BendTT kernel. …

What happened

bend2 accepts duplicate: in the SpineEnd{} arm the type of proof is the
equality {Nat.is_le(b, 7n) == True{} : Bool}, which may be copied. The
translation sees the declared type AtEnd(rest, b), which does not reduce
to a datatype while rest is a variable, and leaves the def out.

Two controls pass both checkers: the same arm calling a helper
pairProof(+b: Nat, +proof: {Nat.is_le(b, 7n) == True{} : Bool}) that returns
(proof, proof); and a hypothesis of computed type consumed once in each
arm, without a copy (whether the match refines its type or not).

What you expected

The kernel checking duplicate, the copy being rebuilt at the type the
match refined it to (an equality, which is data); or, failing that, the
limitation listed in WONTFIX.txt, since --verdict alone only prints the
generic mismatch notice.

bend --version

2.0.35

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions