2009/1/15 Peter Verswyvelen <span dir="ltr"><<a href="mailto:bugfact@gmail.com">bugfact@gmail.com</a>></span><br><div class="gmail_quote"><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
When I first read about active patterns in F#, I found it really cool idea, since it allows creating fake data constructors that can be used for pattern matching, giving many views to a single piece of data, and allowing backwards compatibility when you completely change or hide a data structure.<div>
<br></div><div>So for example one could define a Polar pattern and a Rect pattern that give different views of a Complex number, e.g (pseudo code follows)</div><div><br></div><div>pattern Polar c = (mag c, phase c)</div>
<div>
pattern Rect c = (real c, imag c)</div><div><br></div><div>This seems handy:</div><div><br></div><div>polarMul (Polar m1 p1) (Polar m2 p2) = mkComplexFromPolar (m1*m2) (p1+p2)</div><div><br></div><div>However, I think it is flawed, since the following</div>
<div><br></div><div><div>case c of </div><div> Polar _ _ -> "it's polar!"</div><div> Rect _ _ -> "it's rect!"</div><div><br></div><div>seems like valid code but does not make any sense.</div>
</div></blockquote><div><br>I think it's okay, given that we understand the meanings involved. To me it makes about as much sense as this;<br><br>case c of<br> x -> "it's x!"<br> y -> "it's y!"<br>
<br>Which is just wrong code.<br><br>Maybe the capital letters on Polar and Rect are the confusing bit?<br><br>Luke<br></div></div><br>