Hide this comment

You could create a factory routine:

1
2
3
4
5
6
7
8
type A = 
    | TypeConstructorA of ClassA
    | TypeConstructorB of ClassA
    static member Create (a:ClassA) =
        match a.Type with
        | 0 -> TypeConstructorA a
        | 1 -> TypeConstructorB a
        | _ -> failwith "Invalid Type value"

But it seems to me you may be better of simpling defining some active patterns:

1
2
3
4
let (|TypeConstructorA|_|) (a:ClassA) =
    if a.Type=0 then Some a else None
let (|TypeConstructorB|_|) (a:ClassA) =
    if a.Type=1 then Some a else None
By on 2/11/2009 12:50 AM ()Reply
Hide this comment

What is the use of your second type A? No matter what you do - you allways end up with an ClassA-object.

So just use a function to give you the instantiated objects of this class.

By on 2/10/2009 11:36 PM ()Reply
Hide this comment

This is sort of like an object classifier. We definitly need this because of our design. we need to treat the classA object as different type in F#.

maybe in C#, they are same, but in F#, they should be treated differently.

By on 2/10/2009 11:47 PM ()Reply
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

Logging in...