Pattern matching (with "match with") is the usual way to do.
The Option module has many useful functions you might want to use. To unwrap a value:

1
2
3
4
5
6
let x = Some 2


Option.get x

To test an option, you can use "x.IsNone", "x.IsSome", or "x = None".
For other sum types, you might need to write your own functions or extension methods.

Laurent.

By on 3/31/2011 5:49 PM ()

Why do you need this?

By on 3/31/2011 7:42 AM ()

Hi,

for the first part I would do the same thing that is avaiable for F#'s Option-type. Implement members IsSome/IsNone or HasValue or whatever and maybe add static-checkers as well.

For the second part: yes in this case you'll get an warning and an error at runtime (just try with F#-interactive:

1
2
3
4
5
6
7
8
9
let (Some y) = x;;

----^^^^^^^^

stdin(3,5): warning FS0025: Incomplete pattern matches on this expression. For example, the value 'None' may indicate a case not covered by the pattern(s).

Microsoft.FSharp.Core.MatchFailureException: The match cases were incomplete

at <StartupCode$FSI_0003>.$FSI_0003.main@()
By on 3/22/2011 11:22 PM ()
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