[Haskell-cafe] F# active patterns versus GHC's view

Luke Palmer lrpalmer at gmail.com
Thu Jan 15 20:31:57 EST 2009

2009/1/15 Peter Verswyvelen <bugfact at gmail.com>

> 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.
> 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)
> pattern Polar c = (mag c, phase c)
> pattern Rect c = (real c, imag c)
> This seems handy:
> polarMul (Polar m1 p1) (Polar m2 p2) = mkComplexFromPolar (m1*m2) (p1+p2)
> However, I think it is flawed, since the following
> case c of
>      Polar _ _ -> "it's polar!"
>      Rect _ _ -> "it's rect!"
> seems like valid code but does not make any sense.

I think it's okay, given that we understand the meanings involved.  To me it
makes about as much sense as this;

case c of
    x -> "it's x!"
    y -> "it's y!"

Which is just wrong code.

Maybe the capital letters on Polar and Rect are the confusing bit?

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090115/42d82b06/attachment.htm

More information about the Haskell-Cafe mailing list