eiriktsarpalis / UnitsOfMeasure.Extra

F# units of measure for primitive non-numeric types

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UnitsOfMeasure.Extra

F# Units of Measure for non-numeric types by Eirik Tsarpalis. Compatible with Fable.

Installing

Add the UnitsOfMeasure.Extra package from Nuget or just copy the src/UnitsOfMeasure.Extra.fs file.

Publishing to Nuget

Run npm i && npm run build publish.

Usage

open UnitsOfMeasure.Extra

[<Measure>] type dir
[<Measure>] type file

let inline mkDir x: string<dir> = %% x
let inline mkFile x: string<file> = %% x

let test (dirPath: string<dir>) (fileName: string<file>): unit =
printfn "FULL PATH: %s/%s" %%dirPath %%fileName

let myDir = mkDir "/my/path"
let myFile = mkFile "file.txt"
// let myDir = mkDir 5 // This doesn't compile

test myDir myFile
// test myFile myDir // This doesn't compile

Example in Fable REPL

About

F# units of measure for primitive non-numeric types


Languages

Language:F# 100.0%