Note that there are some explanatory texts on larger screens.

plurals
  1. POoverloading F# active patterns
    text
    copied!<p>I am fairly new to F# and active patterns, and I ran across an anomoly that I can't explain.</p> <pre><code>module Eval = let (|Bet|Pass|) (test:BetChoice) = match test with | BetChoice.Bet -&gt; Bet | BetChoice.Pass -&gt; Pass let (|NoBet|Bet|Pass|) (test:Nullable&lt;BetChoice&gt;) : Choice&lt;unit, unit, unit&gt; = match test.HasValue with | true -&gt; match test.Value with | BetChoice.Bet -&gt; Bet | BetChoice.Pass -&gt; Pass | false -&gt; NoBet let FlipByWinner ((value:int), (awins:bool)) = match awins with | true -&gt; (value, -value) | false -&gt; (-value, value) let Evaluation (awins:bool) (player11:BetChoice) (player21:BetChoice) (player12:Nullable&lt;BetChoice&gt;) = match player11 with | Pass -&gt; match player21 with | Pass -&gt; FlipByWinner(1, awins) | Bet-&gt; match player12 with | Bet -&gt; FlipByWinner(2, awins) | Pass -&gt; FlipByWinner(1, false) | NoBet -&gt; raise (System.ArgumentException("invalid strategy")) | Bet -&gt; match player21 with | Bet -&gt; FlipByWinner (2, awins) | Pass -&gt; FlipByWinner (1, false) </code></pre> <p>This doesn't compile. With a minor tweak I can make it work as intended, but the fact that I don't know exactly what is going on makes me a little nervous... the second pattern can get renamed to "(|NoBet|Bet1|Pass1|)" and it's associated patterns changed throughout the code, then it works, but I don't really get why this has a type mismatch exception.</p> <p>Also is there a good way of dealing with 2 active patterns that are almost identical, but not quite? seems like there should be a way to factor the common stuff together. (as a side note, it looks like the indenting got messed up in the copy/paste, this is all part of the module Eval properly).</p>
 

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