Last active
August 29, 2015 14:15
-
-
Save undeadcat/3916cc75cd3263ff37b8 to your computer and use it in GitHub Desktop.
Units of measure magic
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
let inline retype (t : ^t) :^tm = (# "" t : ^tm #) | |
let inline (++) (w : ^W when ^W : (static member IsMeasureAbbrev : ^tm * ^t -> unit)) (t : ^t) = (# "" t : ^tm #) | |
open System | |
[<MeasureAnnotatedAbbreviation>] | |
type Guid<[<Measure>] 'Measure> = Guid | |
[<MeasureAnnotatedAbbreviation>] | |
type string<[<Measure>] 'Measure> = string | |
type UoM = | |
| UoM | |
static member IsMeasureAbbrev(_ : Guid<'Measure>, _ : Guid) = () | |
static member IsMeasureAbbrev(_ : string<'Measure>, _ : string) = () | |
[<Measure>] | |
type processId | |
[<Measure>] | |
type taskId | |
type Entry = | |
{ ProcessId : Guid<processId> | |
TaskId : Guid<taskId> } | |
let (taskId : Guid<taskId>) = UoM ++ Guid.NewGuid() | |
let (pid : Guid<processId>) = UoM ++ Guid.NewGuid() | |
let entry = | |
{ ProcessId = pid | |
TaskId = taskId } | |
[<EntryPoint>] | |
let main argv = | |
let (taskId : Guid<taskId>) = UoM ++ Guid.NewGuid() | |
let (pid : Guid<processId>) = UoM ++ Guid.NewGuid() | |
let good ={ProcessId = retype (Guid.NewGuid()); TaskId = retype (Guid.NewGuid())} | |
let evil ={ProcessId = retype (Guid.NewGuid()); TaskId = retype (false)} | |
printfn "%A" argv | |
0 // return an integer exit code |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment