Skip to content

Instantly share code, notes, and snippets.

@liammclennan
Last active August 29, 2015 14:07
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 liammclennan/0102bb0fe88fef9abf92 to your computer and use it in GitHub Desktop.
Save liammclennan/0102bb0fe88fef9abf92 to your computer and use it in GitHub Desktop.
type A = { thing: int }
type B = { label: string }
let show (a:A) =
sprintf "%A" a
let show (b:B) =
sprintf "%A" b
{ thing = 98 } |> show |> Console.WriteLine
type IShow =
abstract member show : unit -> string
type A =
{ thing: int }
interface IShow with
member this.show() = sprintf "%A" this
type B =
{ label: string }
interface IShow with
member this.show() = sprintf "%A" this
let show (x:IShow) =
x.show()
{ thing = 98 } |> show |> Console.WriteLine
{ label = "Car" } |> show |> Console.WriteLine
type A = { thing: int }
type B = { label: string }
type ThingThatShows =
static member show(x:A) = sprintf "%A" x
static member show(x:B) = sprintf "%A" x
{ thing = 98 } |> ThingThatShows.show |> Console.WriteLine
{ label = "Car" } |> ThingThatShows.show |> Console.WriteLine
type A = { thing: int }
with static member show a = sprintf "%A" a
type B = { label: string }
with static member show b = sprintf "%A" b
let inline show (x:^t) =
(^t: (static member show: ^t -> string) (x))
{ thing = 98 } |> show |> Console.WriteLine
{ label = "Car" } |> show |> Console.WriteLine
class Showable a where
shw :: a -> String
data A = A String
data B = B Int
instance Showable A where
shw (A s) = s
instance Showable B where
shw (B i) = show i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment