Skip to content

Instantly share code, notes, and snippets.

@bryanhunter
Created November 12, 2017 00:55
Show Gist options
  • Select an option

  • Save bryanhunter/41d5c46464320e15f5812fda9ee4e11f to your computer and use it in GitHub Desktop.

Select an option

Save bryanhunter/41d5c46464320e15f5812fda9ee4e11f to your computer and use it in GitHub Desktop.

Revisions

  1. bryanhunter created this gist Nov 12, 2017.
    17 changes: 17 additions & 0 deletions UnitsOfMeasure.fs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    module UnitsOfMeasure

    [<Measure>] type cm
    [<Measure>] type inch

    type Shape<[<Measure>]'u> =
    | Circle of float<'u>
    | Square of float<'u>
    | Triangle of float<'u> * float<'u>
    | Rectangle of float<'u> * float<'u>

    let GetArea shape =
    match shape with
    | Circle(radius) -> 3.14 * radius * radius
    | Square(width) -> width * width
    | Triangle(``base``, height) -> ``base`` * height / 2.0
    | Rectangle(width, height) -> width * height