Zulip Chat Archive

Stream: new members

Topic: Passing typeclass instances


Antonetta Bado (Jul 29 2025 at 18:12):

import Mathlib

noncomputable section

open MeasureTheory

def f {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P] := 0

example
  {Ω : Type*} [MeasurableSpace Ω]
  {P : Measure Ω} [IsProbabilityMeasure P] {X : Ω  } {X_meas : Measurable X}
  -- need to pass the typeclass instance isProbabilityMeasure_map X_meas.aemeasurable
  : f (P.map X) = 0 := sorry

I get the error failed to synthesize IsProbabilityMeasure (Measure.map X P). Is there a way to manually pass the typeclass instance isProbabilityMeasure_map X_meas.aemeasurable?

Vlad (Jul 29 2025 at 18:57):

https://leanprover.github.io/theorem_proving_in_lean4/Interacting-with-Lean/#named-arguments

Antonetta Bado (Jul 29 2025 at 18:59):

But the parameter has no name. It is just declared as [IsProbabilityMeasure P].

Vlad (Jul 29 2025 at 19:00):

def f  [inst : IsProbabilityMeasure P] := 0

example  : f (P.map X) (inst := ) = 0 := 

Antonetta Bado (Jul 29 2025 at 19:02):

I don't like the idea of changing the definition just so I can pass a typeclass instance. Is there another way to do this?

Kyle Miller (Jul 29 2025 at 19:11):

Using haveI in theorem statements is a way to locally add a definition and have it inline itself immediately. It works for instances too, like this:

import Mathlib

noncomputable section

open MeasureTheory

def f {Ω : Type*} [MeasurableSpace Ω] (P : Measure Ω) [IsProbabilityMeasure P] := 0

example
  {Ω : Type*} [MeasurableSpace Ω]
  {P : Measure Ω} [IsProbabilityMeasure P] {X : Ω  } {X_meas : Measurable X} :
  haveI := isProbabilityMeasure_map (X_meas.aemeasurable (μ := P))
  f (P.map X) = 0 := sorry

Last updated: Dec 20 2025 at 21:32 UTC