Hi Laura,

I think problems is that this is been interpreted as a type or namespace prefix to a union type. I think the solution is move your pattern into a let binding, gives a warning because of the this but basically seems to work:

type MyType() as this =

let (|MyPattern|) ((a,b)) = (this.Convert a, b)

/// any member function

member this.Convert a = a+1

/// method that uses the active pattern

member this.MyMethod x =

match x with

| MyPattern (c,b) -> printfn "%A %A" c b

Cheers,

Rob

By on 12/23/2008 8:11 AM ()

Hi,

Robert beat me to it, but I came up with:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
type MyType() =

    member this.Convert a = a+1

let (|MyPattern|) (this:MyType) (a,b) = (this.Convert a, b)

type MyType with

    member this.MyMethod x =

       match x with

        | MyPattern this (c,b) -> printfn "%A %A" c b 

In all honesty, I would never write that, unless Convert would be a method on some interface that is implemented by several MyTypes. But it is educational in the sense that it points to a key limitation in F#: you need to define almost everything "in order", and you can define mutually referring types and mutually referring functions, but not a mutually referring function and type without resorting to tricks like the above.

have fun with F#,

By on 12/23/2008 8:26 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