css-le-botlan/Y/OCaml/exam2020/Sujet-1/types_filter.ml.html
2021-02-09 17:41:02 +01:00

44 rivejä
No EOL
3,2 KiB
HTML

<!DOCTYPE html>
<!-- Page generated by OCaml with Ocsigen.
See http://ocsigen.org/ and http://caml.inria.fr/ for information -->
<html class="ocaml" lang="fr" id="h" xmlns="http://www.w3.org/1999/xhtml"><head><title>types_filter.ml</title><meta content="text/html; charset=utf-8" http-equiv="content-type"/><link media="all" href="../../../ystyle.css" rel="stylesheet"/><script src="../../../Scripts/yfold.js"></script></head><body><div class="header" id="header"><h1 id="title">types_filter.ml</h1></div><main><div class="download-link"><a class="caml_c" href="../../../Ressources/Ocaml/Corriges-Web/Sujet2020/Sujet-2/types_filter.ml" data-eliom-c-onclick="KA7fhEbmWuTc">Download file: types_filter.ml</a></div><code class="page block">
<span class="comment">(* This is a filter: it tests values of type 'a.
* A filter contains two functions: forbid and f (see the type definition).
*
* We say that a filter:
* - forbids a value x if forbid x returns a non-empty string.
* - accepts a value x if f x returns true
* - rejects a value x if f x returns false
*
* The forbid test is done first: if a value is forbidden, it cannot be accepted or rejected.
*
* Example with an int filter :
* if forbid (-1) returns &quot;a negative number, this is insane!&quot;, this means that -1 is a forbidden value.
* if forbid 12 returns &quot;&quot;, this means that 12 is not forbidden.
*
* if f 12 returns true, this means that 12 is accepted.
* if f 17 returns false, this means that 17 is rejected (assuming 17 is not forbidden either: forbid 17 returns &quot;&quot;)
*)</span>
<span class="kw">type</span> 'a filter =
{ forbid: ('a -&gt; string) ;
f: ('a -&gt; bool) }
<span class="comment">(* When a filter is applied to a value, it returns one of these. *)</span>
<span class="kw">type</span> result = <span class="uident">Forbid</span> <span class="kw">of</span> string | <span class="uident">Accept</span> | <span class="uident">Reject</span>
<span class="comment">(* Forbid contains the message returned by the forbid function.
* It cannot be empty. *)</span>
<span class="comment">(* In some tests, we use some predefined filters :
*
* filter_even : int filter, forbids : negative numbers, accepts : even numbers (2,4,6,8, ...)
* filter_odd : int filter, forbids : 0, accepts : odd numbers (1,3,-5,-7,...)
*
* filter_pair : (int*int) filter, forbids pairs (a,b) when a is a negative number, accepts pairs with equal values, e.g. (4,4)
*
*)</span>
</code></main><footer><small class="pcom"><a class="caml_c" href="../../../yversion.html" data-eliom-c-onclick="tMmOzWhMzM9u">Version information</a></small><a target="_blank" href="http://www.insa-toulouse.fr"><img title="INSA Toulouse" style="width:73px;height:28px;" alt="INSA logo" src="../../../Images/logo-insa-light.jpg"/></a><a target="_blank" href="http://jigsaw.w3.org/css-validator/check/referer"><img title="Validate css stylesheet" style="width:28px;height:32px;" alt="CSS3 logo" src="../../../Images/css3.png"/></a><a target="_blank" href="http://validator.w3.org/check/referer"><img title="Validate html5 content" style="width:32px;height:32px;" alt="HTML5 logo" src="../../../Images/html5.png"/></a></footer></body></html>