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&nbsp;compatibility&nbsp;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&nbsp;</div><div>&nbsp;&nbsp; &nbsp; Polar _ _ -&gt; &quot;it&#39;s polar!&quot;</div><div>&nbsp;&nbsp; &nbsp; Rect _ _ -&gt; &quot;it&#39;s rect!&quot;</div><div><br></div><div>seems like valid code but does not make any sense.</div>
<div><br></div><div>So I think the GHC extension of view patterns is better than the active patterns in F#?</div><div><br></div><div>A good coding style is to provide constructor functions and hide data constructors. But then one looses the ability to perform pattern matching, which is so cool in Haskell. Would I have to conclude that it would be good coding style to use view patterns as much as possible in Haskell, creating&nbsp;auxiliary&nbsp;data constructors to expose the &quot;public members&quot; of the hidden data constructors?</div>
<div><br></div><div><br></div><div><br></div><div><br></div></div>