Skip to content

Instantly share code, notes, and snippets.

@jindraivanek
Created April 20, 2017 22:03
Show Gist options
  • Save jindraivanek/5d01f337ae55b7fef1ad8e490970ccd8 to your computer and use it in GitHub Desktop.
Save jindraivanek/5d01f337ae55b7fef1ad8e490970ccd8 to your computer and use it in GitHub Desktop.
module ShowTrait =
[<Trait>]
type Show<'T> =
abstract member show: 'T -> 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()
[<Witness>]
type ShowSeq<'U, 'T, 'V when 'T :> Show<'U> and 'V :> seq<'U>> =
interface Show<'V> with
member __.show(xs) = xs |> Seq.map Show.show |> String.concat "; "
let show x = Show.show x
open ShowTrait
for i in [1..1000] do
//sprintf "%A" [1..100]
sprintf "%s" <| show [1..100]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment