Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is a very similar function in the <code>List</code> theory in the standard library. That function takes a predicate as an argument, i.e. a function <code>f</code> from the element type to <code>bool</code>, and it returns <code>Some x</code> if a matching element <code>x</code> is found, or <code>None</code> if none is found.</p> <pre><code>Variable A : Type. Fixpoint find (f:A-&gt;bool) (l:list A) : option A := match l with | nil =&gt; None | x :: tl =&gt; if f x then Some x else find tl end. </code></pre> <p>You're looking for an element that's equal to a particular object <code>a</code>. That means your predicate is <code>eq_Interface a</code>, where <code>eq_Interface</code> is the equality you want over the <code>Interface</code>.</p> <p>It's up to you to define an equality function on your type, because there can be many definitions of equality. Coq defines <code>=</code>, which is <a href="http://en.wikipedia.org/wiki/Leibniz%27s_law" rel="nofollow">Leibniz equality</a>: two values are equal iff there is no way to distinguish between them. <code>=</code> is a proposition, not a boolean, because this property is not decidable in general. It's also not always the desirable equality on a type, sometimes you want a coarser equivalence relation, so that two objects can be considered equal if they were constructed in different ways but nonetheless have the same meaning.</p> <p>If <code>Interface</code> is a simple datatype — intuitively, a data structure with no embedded proposition — there's a built-in tactic to build a structural equality function from the type definition. Look up <code>decide equality</code> in the reference manual.</p> <pre><code>Definition Interface_dec : forall x y : Interface, {x=y} + {x &lt;&gt; y}. Proof. decide equality. Defined. Definition Interface_eq x y := if Interface_dec x y then true else false. </code></pre> <p><code>Interface_dec</code> not only tells you whether its arguments are equal, but also comes with a proof that the arguments are equal or that they're different.</p> <p>Once you have that equality function, you can define your <code>find</code> function in terms of the standard library function:</p> <pre><code>Definition Interface_is_in x := if List.find (Interface_eq x) then true else false. </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload