Created
June 17, 2015 17:08
-
-
Save TIHan/85ac6dc788acdc42de3b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
namespace Styles | |
// Style 1; OCaml Style | |
module Basketball = | |
type T = | |
{ | |
Weight: int | |
} | |
let create weight = | |
{ | |
Weight = weight | |
} | |
let print (a: T) = printfn "%s" <| a.ToString () | |
// Style 2; F# Standard Library | |
type Baseball = | |
{ | |
Weight: int | |
} | |
[<RequireQualifiedAccess; CompilationRepresentation (CompilationRepresentationFlags.ModuleSuffix)>] | |
module Baseball = | |
let create weight = | |
{ | |
Weight = weight | |
} | |
let print (a: Baseball) = printfn "%s" <| a.ToString () | |
// Style 3; Immutable .NET; WebSharper | |
type Football = | |
{ | |
Weight: int | |
} | |
static member Create weight = | |
{ | |
Weight = weight | |
} | |
static member Print (a: Football) = printfn "%s" <| a.ToString () | |
// Style 4; Immutable .NET | |
type Ball = | |
{ | |
Weight: int | |
} | |
static member Create weight = | |
{ | |
Weight = weight | |
} | |
member this.Print () = printfn "%s" <| this.ToString () | |
// Style 5; Maybe more of OCaml? Not recommended because types should be PascalCase | |
type softball = | |
{ | |
weight: int | |
} | |
module Softball = | |
let create weight = | |
{ | |
weight = weight | |
} | |
let print (a: softball) = printfn "%s" <| a.ToString () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment