Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>All the <code>Text.Regex.*</code> modules make heavy use of typeclasses, which are there for extensibility and "overloading"-like behavior, but make usage less obvious from just seeing types.</p> <p>Now, you've probably been started off from the basic <code>=~</code> matcher.</p> <pre><code>(=~) :: ( RegexMaker Regex CompOption ExecOption source , RegexContext Regex source1 target ) =&gt; source1 -&gt; source -&gt; target (=~~) :: ( RegexMaker Regex CompOption ExecOption source , RegexContext Regex source1 target, Monad m ) =&gt; source1 -&gt; source -&gt; m target </code></pre> <p>To use <code>=~</code>, there must exist an instance of <code>RegexMaker ...</code> for the LHS, and <code>RegexContext ...</code> for the RHS and result.</p> <pre><code>class RegexOptions regex compOpt execOpt | ... | regex -&gt; compOpt execOpt , compOpt -&gt; regex execOpt , execOpt -&gt; regex compOpt class RegexOptions regex compOpt execOpt =&gt; RegexMaker regex compOpt execOpt source | regex -&gt; compOpt execOpt , compOpt -&gt; regex execOpt , execOpt -&gt; regex compOpt where makeRegex :: source -&gt; regex makeRegexOpts :: compOpt -&gt; execOpt -&gt; source -&gt; regex </code></pre> <p>A valid instance of all these classes (for example, <code>regex=Regex</code>, <code>compOpt=CompOption</code>, <code>execOpt=ExecOption</code>, and <code>source=String</code>) means it's possible to compile a <code>regex</code> with <code>compOpt,execOpt</code> options from some form <code>source</code>. (Also, given some <code>regex</code> type, there is exactly one <code>compOpt,execOpt</code> set that goes along with it. Lots of different <code>source</code> types are okay, though.)</p> <pre><code>class Extract source class Extract source =&gt; RegexLike regex source class RegexLike regex source =&gt; RegexContext regex source target where match :: regex -&gt; source -&gt; target matchM :: Monad m =&gt; regex -&gt; source -&gt; m target </code></pre> <p>A valid instance of all these classes (for example, <code>regex=Regex</code>, <code>source=String</code>, <code>target=Bool</code>) means it's possible to match a <code>source</code> and a <code>regex</code> to yield a <code>target</code>. (Other valid <code>target</code>s given these specific <code>regex</code> and <code>source</code> are <code>Int</code>, <code>MatchResult String</code>, <code>MatchArray</code>, etc.)</p> <p>Put these together and it's pretty obvious that <code>=~</code> and <code>=~~</code> are simply convenience functions</p> <pre><code>source1 =~ source = match (makeRegex source) source1 source1 =~~ source = matchM (makeRegex source) source1 </code></pre> <p>and also that <code>=~</code> and <code>=~~</code> leave no room to pass various options to <code>makeRegexOpts</code>.</p> <p>You could make your own</p> <pre><code>(=~+) :: ( RegexMaker regex compOpt execOpt source , RegexContext regex source1 target ) =&gt; source1 -&gt; (source, compOpt, execOpt) -&gt; target source1 =~+ (source, compOpt, execOpt) = match (makeRegexOpts compOpt execOpt source) source1 (=~~+) :: ( RegexMaker regex compOpt execOpt source , RegexContext regex source1 target, Monad m ) =&gt; source1 -&gt; (source, compOpt, execOpt) -&gt; m target source1 =~~+ (source, compOpt, execOpt) = matchM (makeRegexOpts compOpt execOpt source) source1 </code></pre> <p>which could be used like</p> <pre><code>"string" =~+ ("regex", CompCaseless + compUTF8, execBlank) :: Bool </code></pre> <p>or overwrite <code>=~</code> and <code>=~~</code> with methods which can accept options</p> <pre><code>import Text.Regex.PCRE hiding ((=~), (=~~)) class RegexSourceLike regex source where makeRegexWith source :: source -&gt; regex instance RegexMaker regex compOpt execOpt source =&gt; RegexSourceLike regex source where makeRegexWith = makeRegex instance RegexMaker regex compOpt execOpt source =&gt; RegexSourceLike regex (source, compOpt, execOpt) where makeRegexWith (source, compOpt, execOpt) = makeRegexOpts compOpt execOpt source source1 =~ source = match (makeRegexWith source) source1 source1 =~~ source = matchM (makeRegexWith source) source1 </code></pre> <p>or you could just use <code>match</code>, <code>makeRegexOpts</code>, etc. directly where needed.</p>
    singulars
    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. 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.
 

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