Just change the type name to Option with a capital O. type abreviations can not have augmentations.

also note that the type parameter goes onto the type name NOT the method:

1
2
3
4
5
6
7
let r = box 4.0 |> option<float>.Cast

//NOT

let r = box 4.0 |> option.Cast<float> // this causes a type application error

By on 4/3/2010 9:27 PM ()

Cool beans - thanks. The extension method compiles and runs as expected:

1
2
3
4
5
6
type Microsoft.FSharp.Core.Option<'T> with 
    static member Cast<'T> (x:obj) : 'T option =
        if x = null then None else Some (x :?> 'T)

let inline Optional<'T> (x:obj) : 'T option = 
    if x = null then None else Some (x :?> 'T)

box 3 |> Option<int>.Cast
null |> Option<int>.Cast
or
box 3 |> Optional<int>
null |> Optional<int>

The former seems to jibe with Seq.Cast and seems like a natural to include to me - tho' the latter is less verbose and inlined.

By on 4/3/2010 10:10 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