Last active
August 29, 2015 14:07
-
-
Save liammclennan/0102bb0fe88fef9abf92 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
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 |
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
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 |
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
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 |
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
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 |
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
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