Skip to content

Instantly share code, notes, and snippets.

@jindraivanek
Created May 31, 2017 17:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jindraivanek/4d461800cfc9d1bf33507c783aec5712 to your computer and use it in GitHub Desktop.
Save jindraivanek/4d461800cfc9d1bf33507c783aec5712 to your computer and use it in GitHub Desktop.
module T =
open System
[<Trait>]
type Show<'a> =
abstract member show: 'a -> string
[<Witness>]
type ShowInt =
interface Show<int> with
member __.show x = x.ToString()
[<Witness>]
type ShowFloat =
interface Show<float> with
member __.show x = x.ToString()
let inline show'< ^w, ^a when ^w : (member show : ^a -> string)> (w: 'w, a: 'a) =
(^w: (member show : 'a -> string) Unchecked.defaultof<'w>, a)
let inline show x = show'(Unchecked.defaultof<_>, x)
//error FS0332: Could not resolve the ambiguity inherent in the use of the operator 'show' at or near this program point. Consider using type annotations to resolve the ambiguity.
//error FS0071: Type constraint mismatch when applying the default type 'obj' for a type inference variable. The type 'obj' does not support the operator 'show' Consider adding further type constraints
show 1 |> printfn "%s"
show 1.0 |> printfn "%s"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment