Record pattern works, too:

1
let f ({ x = x; y = y } : Pair) = ...

Now don't ask me why that works on non-record types :) . I guess it's a compiler bug.

By on 6/8/2009 10:58 AM ()

but it would not compile.

Related question is whether there is efficiency hit due to active patterns. For example, when I have
match pair with
|Pair (start, len) -> start+len
does the compiler create a tuple (start, len) as an intermediate, before binding "start" and "len"?

Your code compiled and worked when I tried it...?There is an efficiency "hit" in the sense that active patterns are basically just syntactic sugar for functions. So there is a function call involved, so I guess it'll create a tuple as well. Not sure how well the compiler or JIT is able to compile this away. In any case, you'd have to use that in a really tight and fast loop before it starts to matter, I think.

By on 6/8/2009 3:51 AM ()

I guess I originally mistyped it... Now it compiles for me as well.

but it would not compile.

Related question is whether there is efficiency hit due to active patterns. For example, when I have
match pair with
|Pair (start, len) -> start+len
does the compiler create a tuple (start, len) as an intermediate, before binding "start" and "len"?

Your code compiled and worked when I tried it...?There is an efficiency "hit" in the sense that active patterns are basically just syntactic sugar for functions. So there is a function call involved, so I guess it'll create a tuple as well. Not sure how well the compiler or JIT is able to compile this away. In any case, you'd have to use that in a really tight and fast loop before it starts to matter, I think.

By on 6/8/2009 9:40 AM ()

>> Your code compiled and worked when I tried it...?

Yep - worked when I tried it. [F# 1.9.6.16]

By on 6/8/2009 4:06 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper