[Haskell-cafe] F# active patterns versus GHC's view
bugfact at gmail.com
Fri Jan 16 05:24:02 EST 2009
On Fri, Jan 16, 2009 at 2:31 AM, Luke Palmer <lrpalmer at gmail.com> wrote:
> 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.
Okay, so you're saying that these mistakes can't occur since the it will
give a syntax error? Fair point.
Maybe the capital letters on Polar and Rect are the confusing bit?
I don't think so since that is the whole point of Active Patterns in F#.
Suppose you initially made something like:
data Bla = Dog Int | Cat Float
and a lot of clients of your code us the Dog and Cat data constructors
After a while you decide that you need to change the Bla data type, maybe
give Dog more fields, maybe completely redesign it, maybe not exposing it,
but you want to keep existing code backwards compatible. With F# you can
write Active Patterns for the old Dog and Cat constructors, so all existing
code remains compatible. At least that is the way I understand it, but I
have not actually worked yet with Active Patterns, will do so soon :)
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe