I don't think it's directly possible. This is IMO one of the biggest weaknesses/holes in the language (can't have mutually recursive types span modules/namespaces). However you can extend your workaround idea with Active Patterns thusly:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
module Hide =
    type A = 
        | A1 of int
        | A2 of B
    and B =
        | B1 of string
        | B2 of A
module AStuff =
    type A = Hide.A
    let A1 = Hide.A1
    let A2 = Hide.A2
    let (|A1|A2|) = function
        | Hide.A1 x -> A1(x)
        | Hide.A2 x -> A2(x)
module BStuff =
    type B = Hide.B
    let B1 = Hide.B1
    let B2 = Hide.B2
    let (|B1|B2|) = function
        | Hide.B1 x -> B1(x)
        | Hide.B2 x -> B2(x)
module Main =
    open AStuff
    open BStuff
    let z = if true then A1 42 else A2(B2(A1 42))
    match z with
    | A1 x -> ()
    | A2 b -> ()
By on 6/8/2010 7:11 AM ()

Ah!

Great idea, that will do perfectly.

Thanks a lot Brian,

Vincent

Edit:

note to F# developers: a "perfect" workaround, but not having to multiply code length by 3 would be nicer :-)

By on 6/8/2010 8:09 AM ()

And now is the moment that I get to learn about the seven tag limit *sigh*

By on 6/8/2010 8:59 AM ()

How many DU tags do you have?

By on 6/8/2010 10:43 AM ()

7 and 8, for now.

Those DU's are protocol packets. Having two agents with 2-way communication creates the above problem, and I can't convince myself that 2-way communication is a Bad Design Decision.

For now I've left the less frequently used protocol packet out of the active pattern (i.e. I have to get to the data constructor in the long winded way). The lack of consistency is annoying but for now your active pattern solution is Almost Perfect so we'll stick to it until (if) we figure some other way.

By on 6/8/2010 11:02 AM ()

I consider this is solved, but if someone comes up with a solution that preserves match exhaustiveness analysis, please tell me about it.

Oh, also:

I suppose this must be documented elsewhere, but is there a way to tell the compiler to not produce a warning about incomplete matches? I'd rather put a big warning over the code than encourage ignoring the other important exhaustiveness warnings.

Thanks,

By on 6/9/2010 10:13 AM ()

You can use the --nowarn:number flag on the compiler

[link:msdn.microsoft.com]

the 'suppress warnings' (by number) dialog on the project properties in visual studio (both of which disable the warning for the whole compilation), or e.g.

#nowarn "42"

in the source code to turn off that warning for just that file. (There's no way to turn off the warning on a single case-by-case basis; just add e.g.

| _ -> failwith "never get here"

or something.)

You should see the warning number about exhaustiveness in the build output, e.g.

C:\Users\brianmcn\Documents\Visual Studio 2010\Projects\ConsoleApplication5\ConsoleApplication5\Program.fs(12,7): warning FS0025: Incomplete pattern matches on this expression. For example, the value 'Some (_)' may indicate a case not covered by the pattern(s).

By on 6/9/2010 10:36 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