Created
May 31, 2017 17:44
-
-
Save jindraivanek/4d461800cfc9d1bf33507c783aec5712 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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