6 people like it.

Function overload

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

type WriteAnyOverloads = WriteAnyOverloads with
    static member inline ($) (x: char, _) = Console.Write x
    static member inline ($) (x: string, _) = Console.Write x

let inline write any = any $ WriteAnyOverloads

write "1" //OK
write '1' //OK
//write  1  //NOT OK
namespace System
Multiple items
union case WriteAnyOverloads.WriteAnyOverloads: WriteAnyOverloads

--------------------
type WriteAnyOverloads =
  | WriteAnyOverloads
  static member ( $ ) : x:char * 'a -> unit
  static member ( $ ) : x:string * 'a -> unit

Full name: Script.WriteAnyOverloads
val x : char
Multiple items
val char : value:'T -> char (requires member op_Explicit)

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

--------------------
type char = Char

Full name: Microsoft.FSharp.Core.char
type Console =
  static member BackgroundColor : ConsoleColor with get, set
  static member Beep : unit -> unit + 1 overload
  static member BufferHeight : int with get, set
  static member BufferWidth : int with get, set
  static member CapsLock : bool
  static member Clear : unit -> unit
  static member CursorLeft : int with get, set
  static member CursorSize : int with get, set
  static member CursorTop : int with get, set
  static member CursorVisible : bool with get, set
  ...

Full name: System.Console
Console.Write(value: string) : unit
   (+0 other overloads)
Console.Write(value: obj) : unit
   (+0 other overloads)
Console.Write(value: uint64) : unit
   (+0 other overloads)
Console.Write(value: int64) : unit
   (+0 other overloads)
Console.Write(value: uint32) : unit
   (+0 other overloads)
Console.Write(value: int) : unit
   (+0 other overloads)
Console.Write(value: float32) : unit
   (+0 other overloads)
Console.Write(value: decimal) : unit
   (+0 other overloads)
Console.Write(value: float) : unit
   (+0 other overloads)
Console.Write(buffer: char []) : unit
   (+0 other overloads)
val x : string
Multiple items
val string : value:'T -> string

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

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

Full name: Microsoft.FSharp.Core.string
val write : any:'a -> '_arg3 (requires member ( $ ))

Full name: Script.write
val any : 'a (requires member ( $ ))
Raw view Test code New version

More information

Link:http://fssnip.net/7Xj
Posted:4 years ago
Author:
Tags: