Skip to content

Instantly share code, notes, and snippets.

@TIHan
Created June 17, 2015 17:08
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 TIHan/85ac6dc788acdc42de3b to your computer and use it in GitHub Desktop.
Save TIHan/85ac6dc788acdc42de3b to your computer and use it in GitHub Desktop.
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