No. (The same problem exists in C#, various static-analysis tools will force/encourage you to write a "default" clause in your 'switch'.) This is just a consequence of .Net enums being represented by an underlying integer type that contains more possible values than there are in an enumeration.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 

type MyEnum =
    | One = 1
    | Two = 2

let f x =
    match x with
    | MyEnum.One -> "one"
    | MyEnum.Two -> "two"
    | _ -> failwith "some other bad value"


let s = f (enum 0)    
By on 1/13/2010 8:35 AM ()

You can disable the warning, but in that case you'll probably miss it in many other places where it would be useful (so it is probably not a good idea to do this). Anyway:

1
2
3
4
5
#nowarn "25"
let f x =
    match x with
    | MyEnum.One -> "one"
    | MyEnum.Two -> "two"

As far as I know, this can be done only in a per-file scope, so it's not as useful.

By on 1/13/2010 9:30 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