Someone else already posted the correct way to do what you're trying here (using the :? pattern for type testing).

I just wanted to point out that in this code:

let x = typeof<System.Single>
match t with
| x -> "Single"

the second 'x' is a fresh pattern variable (shadowing the first 'x') which will match anything (which explains the compiler warning about further rules never being matched).

By on 9/10/2008 4:11 PM ()
1
2
3
4
let foo (t: obj) =
  match t with
  | :? System.Single -> "Single"
  | _ -> "Any type"
By on 9/10/2008 3:35 PM ()

yes I know about the :? operator, but I need a function that takes a System.Type as an input.

thanks,

Russell

By on 9/10/2008 4:14 PM ()
1
2
3
4
let foo (t: System.Type) =
  match t with
  | _ when t = typeof<float32> -> "Single"
  | _ -> "Any type"
By on 9/10/2008 4:23 PM ()

Works now! Thanks yashez!

brian: ok I understood my mistake, thanks!

By on 9/10/2008 4:30 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