2
$\begingroup$
def IsEven: Nat → Prop
| Nat.zero => True
| Nat.succ pred => ¬IsEven pred

inductive Example: Nat → Prop
| IsExample: IsEven n → Example (n + 10)

Here, IsExample has an implicit parameter n. Let's say I have a value of type Example m, and in order to use it in a proof, I need to refer to the n. How can I do that?

def sillyExampleFunction
  (e: Example m)
:
  IsEven m
:=
  match e with
  | Example.IsExample isEven =>
    -- How may I access the value of `n` here?
    sorry

For implicit function parameters, this is possible with function literals by putting the implicit parameters inside curly braces:

def IsMonotonic
  (fn: Nat → Nat)
:=
  -- `n0` and `n1` are implicit parameters.
  ∀ {n0 n1: Nat}, n0 ≤ n1 → fn n0 ≤ fn n1

def doubleIsMono:
  IsMonotonic (fun n => 2 * n)
:=
  fun {n0 n1} le =>
    -- Here we may use `n0` and `n1` in our proof.
    sorry

I've tried matching with

  | Example.IsExample {n} isEven => sorry

but I'm getting the error "too many arguments".

$\endgroup$

1 Answer 1

5
$\begingroup$

In Lean @foo is like foo but with all arguments made explicit, see documentation on implicit arguments (search for @). To pattern-match against implicit arguments, use the @foo variant, as in this simple example:

inductive Cow : Type
| moo : ∀ {k : Nat}, k = 42 → Cow

-- moo has an implicit argument k

def milk : Cow → Prop
| @Cow.moo k p => (p = p) ∧ (k = k)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.