Skip to content
Snippets Groups Projects

Replace `MGuard` with `MFail`

Closed Adam requested to merge adamAndMath/stdpp:adamAndMath/mfail into master
4 unresolved threads

This MR implements MFail as described in #171. This replaces mguard with guard : P → {Decision P} → M P using mfail. As such I've replaced guard P; mx with _ ← guard P; mx in all lemmas. This MR further more replaces case_option_guard with a more general case_guard.

These changes are very much breaking changes.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
941 941 End fin_to_set.
942 942
943 943 (** * Guard *)
944 Global Instance set_guard `{MonadSet M} : MGuard M :=
945 λ P dec A x, match dec with left H => x H | _ => end.
944 Global Instance set_mfail `{MonadSet M} : MFail M := λ _, ∅.
946 945
947 946 Section set_monad_base.
948 947 Context `{MonadSet M}.
949 948
950 949 Lemma elem_of_guard `{Decision P} {A} (x : A) (X : M A) :
951 (x guard P; X) P x X.
950 x (guard P;; X) P x X.
  • I think this lemma should just be there for x ∈ guard P, also the instance set_unfold_guard below.

    I don't know whether it's worth to still have the version for combined bind + guard.

  • I am not sure what you want the lemma to state, because x ∈ guard P ↔ decide P = left x. To avoid talking about equality of proofs we'd need either proof irrelevance or, to forget the proof using either fmap or mbind. This is the main reason I've kept the binds. Could you clarify what you want the lemma to state?

  • You are right. This is the same problem as decide_True which includes an if.

    Would be good to include a comment to explain what you wrote here.

  • I've now added a comment. Though I'm uncertain whether it's expansive enough.

  • Please register or sign in to reply
  • 411 destruct_decide (@decide P dec) as Hx
    412 end.
    413 Tactic Notation "case_option_guard" :=
    414 let H := fresh in case_option_guard as H.
    415 400
    416 401 Lemma option_guard_True {A} P `{Decision P} (mx : option A) :
    417 P mguard P (λ _, mx) = mx.
    418 Proof. intros. by case_option_guard. Qed.
    419 Lemma option_guard_True_pi {A} P `{Decision P, ProofIrrel P} (f : P option A)
    420 (HP : P) :
    421 mguard P f = f HP.
    422 Proof. intros. case_option_guard; [|done]. f_equal; apply proof_irrel. Qed.
    423 Lemma option_guard_False {A} P `{Decision P} (f : P option A) :
    424 ¬P mguard P f = None.
    425 Proof. intros. by case_option_guard. Qed.
    402 P (guard P;; mx) = mx.
  • I very much like this MR; thank you. I have some comments about the lemmas.

    This MR also needs a changelog entry.

  • Could you add a CHANGELOG entry?

  • Adam added 2 commits

    added 2 commits

    • 47941c3e - Add changelog entries for MFail
    • c9d008d2 - Add comment justifying use of bind in lemmas

    Compare with previous version

  • 401 (** * Tactics *)
    402 Tactic Notation "case_option_guard" "as" ident(Hx) :=
    403 match goal with
    404 | H : context C [@mguard option _ ?P ?dec] |- _ =>
    405 change (@mguard option _ P dec) with (λ A (f : P option A),
    406 match @decide P dec with left H' => f H' | _ => None end) in *;
    407 destruct_decide (@decide P dec) as Hx
    408 | |- context C [@mguard option _ ?P ?dec] =>
    409 change (@mguard option _ P dec) with (λ A (f : P option A),
    410 match @decide P dec with left H' => f H' | _ => None end) in *;
    411 destruct_decide (@decide P dec) as Hx
    412 end.
    413 Tactic Notation "case_option_guard" :=
    414 let H := fresh in case_option_guard as H.
    415
    400 (**
    • Suggested change
      391 (**
      392 This lemma includes a bind, to avoid equalities of proofs.
      393 A direct proof that `guard P = Some p` would require `decide P = left p`.
      394 *)
      391 (** This lemma includes a bind, to avoid equalities of proofs. We cannot have
      392 [guard P = Some p ↔ P] unless [P] is proof irrelant. The best (but less usable)
      393 self-contained alternative would be [guard P = Some p ↔ decide P = left p]. *)

      How about this?

    • Adam changed this line in version 5 of the diff

      changed this line in version 5 of the diff

    • Updated both comments to match your suggestion.

    • Please register or sign in to reply
  • Adam added 1 commit

    added 1 commit

    Compare with previous version

  • Thibaut Pérami mentioned in merge request !501 (closed)

    mentioned in merge request !501 (closed)

  • mentioned in merge request adamAndMath/stdpp!1 (merged)

  • Adam added 2 commits

    added 2 commits

    • 21c072dc - Replace MFail by MThrow
    • ceb4b297 - Merge branch 'mthrow' into 'adamAndMath/mfail'

    Compare with previous version

  • Thibaut Pérami mentioned in merge request !522 (merged)

    mentioned in merge request !522 (merged)

  • This can be closed as it is being superseded by !522 (merged)

    Edited by Thibaut Pérami
  • Closing. Let's continue discussion in the new MR.

  • Please register or sign in to reply
    Loading