0 people like it.

Pattern matching over generic types

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
open System

let helloWorld () =
  match Some "Hello World!" with
  | Some value -> 
    match box value with
    | :? string as greeting -> printfn "%s" greeting
    | _ -> ()  
  | _ -> ()

helloWorld ()
namespace System
val helloWorld : unit -> unit

Full name: Script.helloWorld
union case Option.Some: Value: 'T -> Option<'T>
val value : string
val box : value:'T -> obj

Full name: Microsoft.FSharp.Core.Operators.box
Multiple items
val string : value:'T -> string

Full name: Microsoft.FSharp.Core.Operators.string

--------------------
type string = String

Full name: Microsoft.FSharp.Core.string
val greeting : string
val printfn : format:Printf.TextWriterFormat<'T> -> 'T

Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Raw view Test code New version

More information

Link:http://fssnip.net/j3
Posted:12 years ago
Author:
Tags: