diff --git a/src/FSharp.UMX.fs b/src/FSharp.UMX.fs index 3a25e05..c16c5e8 100644 --- a/src/FSharp.UMX.fs +++ b/src/FSharp.UMX.fs @@ -9,8 +9,10 @@ open System [] type bool<[] 'm> = bool [] type byte<[] 'm> = byte +[] type uint16<[] 'm> = uint16 [] type uint64<[] 'm> = uint64 [] type Guid<[] 'm> = Guid +[] type char<[] 'm> = char [] type string<[] 'm> = string [] type TimeSpan<[] 'm> = TimeSpan [] type DateTime<[] 'm> = DateTime @@ -18,6 +20,8 @@ open System #if NET6_0_OR_GREATER [] type DateOnly<[] 'm> = DateOnly [] type TimeOnly<[] 'm> = TimeOnly +#else +[] type uint32<[] 'm> = uint32 #endif module private Unsafe = @@ -32,14 +36,17 @@ type UMX = static member inline tag<[]'m> (x : bool) : bool<'m> = Unsafe.cast x static member inline tag<[]'m> (x : byte) : byte<'m> = Unsafe.cast x + static member inline tag<[]'m> (x : sbyte) : sbyte<'m> = Unsafe.cast x static member inline tag<[]'m> (x : int) : int<'m> = Unsafe.cast x static member inline tag<[]'m> (x : int16) : int16<'m> = Unsafe.cast x static member inline tag<[]'m> (x : int64) : int64<'m> = Unsafe.cast x + static member inline tag<[]'m> (x : uint16) : uint16<'m> = Unsafe.cast x static member inline tag<[]'m> (x : uint64) : uint64<'m> = Unsafe.cast x static member inline tag<[]'m> (x : float32) : float32<'m> = Unsafe.cast x static member inline tag<[]'m> (x : float) : float<'m> = Unsafe.cast x static member inline tag<[]'m> (x : decimal) : decimal<'m> = Unsafe.cast x static member inline tag<[]'m> (x : Guid) : Guid<'m> = Unsafe.cast x + static member inline tag<[]'m> (x : char) : char<'m> = Unsafe.cast x static member inline tag<[]'m> (x : string) : string<'m> = Unsafe.cast x static member inline tag<[]'m> (x : TimeSpan) : TimeSpan<'m> = Unsafe.cast x static member inline tag<[]'m> (x : DateTime) : DateTime<'m> = Unsafe.cast x @@ -47,18 +54,24 @@ type UMX = #if NET6_0_OR_GREATER static member inline tag<[]'m> (x : DateOnly) : DateOnly<'m> = Unsafe.cast x static member inline tag<[]'m> (x : TimeOnly) : TimeOnly<'m> = Unsafe.cast x + static member inline tag<[]'m> (x : uint) : uint<'m> = Unsafe.cast x +#else + static member inline tag<[]'m> (x : uint32) : uint32<'m> = Unsafe.cast x #endif static member inline untag<[]'m> (x : bool<'m>) : bool = Unsafe.cast x static member inline untag<[]'m> (x : byte<'m>) : byte = Unsafe.cast x + static member inline untag<[]'m> (x : sbyte<'m>) : sbyte = Unsafe.cast x static member inline untag<[]'m> (x : int<'m>) : int = Unsafe.cast x static member inline untag<[]'m> (x : int16<'m>) : int16 = Unsafe.cast x static member inline untag<[]'m> (x : int64<'m>) : int64 = Unsafe.cast x + static member inline untag<[]'m> (x : uint16<'m>) : uint16 = Unsafe.cast x static member inline untag<[]'m> (x : uint64<'m>) : uint64 = Unsafe.cast x static member inline untag<[]'m> (x : float32<'m>) : float32 = Unsafe.cast x static member inline untag<[]'m> (x : float<'m>) : float = Unsafe.cast x static member inline untag<[]'m> (x : decimal<'m>) : decimal = Unsafe.cast x static member inline untag<[]'m> (x : Guid<'m>) : Guid = Unsafe.cast x + static member inline untag<[]'m> (x : char<'m>) : char = Unsafe.cast x static member inline untag<[]'m> (x : string<'m>) : string = Unsafe.cast x static member inline untag<[]'m> (x : TimeSpan<'m>) : TimeSpan = Unsafe.cast x static member inline untag<[]'m> (x : DateTime<'m>) : DateTime = Unsafe.cast x @@ -66,18 +79,24 @@ type UMX = #if NET6_0_OR_GREATER static member inline untag<[]'m> (x : DateOnly<'m>) : DateOnly = Unsafe.cast x static member inline untag<[]'m> (x : TimeOnly<'m>) : TimeOnly = Unsafe.cast x + static member inline untag<[]'m> (x : uint<'m>) : uint = Unsafe.cast x +#else + static member inline untag<[]'m> (x : uint32<'m>) : uint32 = Unsafe.cast x #endif static member inline cast<[]'m1, []'m2> (x : bool<'m1>) : bool<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : byte<'m1>) : byte<'m2> = Unsafe.cast x + static member inline cast<[]'m1, []'m2> (x : sbyte<'m1>) : sbyte<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : int<'m1>) : int<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : int16<'m1>) : int16<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : int64<'m1>) : int64<'m2> = Unsafe.cast x + static member inline cast<[]'m1, []'m2> (x : uint16<'m1>) : uint16<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : uint64<'m1>) : uint64<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : float<'m1>) : float<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : float32<'m1>) : float32<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : decimal<'m1>) : decimal<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : Guid<'m1>) : Guid<'m2> = Unsafe.cast x + static member inline cast<[]'m1, []'m2> (x : char<'m1>) : char<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : string<'m1>) : string<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : TimeSpan<'m1>) : TimeSpan<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : DateTime<'m1>) : DateTime<'m2> = Unsafe.cast x @@ -85,6 +104,9 @@ type UMX = #if NET6_0_OR_GREATER static member inline cast<[]'m1, []'m2> (x : DateOnly<'m1>) : DateOnly<'m2> = Unsafe.cast x static member inline cast<[]'m1, []'m2> (x : TimeOnly<'m1>) : TimeOnly<'m2> = Unsafe.cast x + static member inline cast<[]'m1, []'m2> (x : uint<'m1>) : uint<'m2> = Unsafe.cast x +#else + static member inline cast<[]'m1, []'m2> (x : uint32<'m1>) : uint32<'m2> = Unsafe.cast x #endif diff --git a/src/FSharp.UMX.fsproj b/src/FSharp.UMX.fsproj index 07a6c1e..25c73a8 100644 --- a/src/FSharp.UMX.fsproj +++ b/src/FSharp.UMX.fsproj @@ -28,6 +28,7 @@ - + + diff --git a/tests/FSharp.UMX.Tests.fs b/tests/FSharp.UMX.Tests.fs index ea4fcfa..d558e4b 100644 --- a/tests/FSharp.UMX.Tests.fs +++ b/tests/FSharp.UMX.Tests.fs @@ -31,10 +31,17 @@ let ``Simple unit of measure conversions with cast operator``() = let x : Guid = % Guid.NewGuid() let y : string = % (%x).ToString() let z : int = % 42 + let uz : uint = % 42u + let uz32 : uint32 = % 42u + let c : char = % 'c' let w : string = % sprintf "%O %s %d" %x %y %z let b : byte = % 1uy + let sb : sbyte = % 1y let s : int16 = % 1s - let f : float32 = % 10.0f + let us : uint16 = % 1us + let l : int64 = % 42L + let ul : uint64 = % 42UL + let f : float32 = % 10.0f let d : DateTime = % DateTime.Now let don : DateOnly = % DateOnly.FromDateTime(DateTime.Now) let ton : TimeOnly = % TimeOnly.FromDateTime(DateTime.Now) @@ -42,12 +49,18 @@ let ``Simple unit of measure conversions with cast operator``() = [] let ``Simple unit of measure conversions with UMX.tag function``() = - let x = UMX.tag (Guid.NewGuid()) - let y = UMX.tag ((%x).ToString()) - let z = UMX.tag (42) - let w = UMX.tag (sprintf "%O %s %d" %x %y %z) - let b = UMX.tag (1uy) - let s = UMX.tag (1s) + let x = UMX.tag (Guid.NewGuid()) + let y = UMX.tag ((%x).ToString()) + let z = UMX.tag (42) + let uz = UMX.tag (42u) + let c = UMX.tag ('c') + let w = UMX.tag (sprintf "%O %s %d" %x %y %z) + let b = UMX.tag (1uy) + let sb = UMX.tag (1y) + let s = UMX.tag (1s) + let us = UMX.tag (1us) + let l = UMX.tag (1l) + let ul = UMX.tag (1UL) let f = UMX.tag (10.0f) let d = UMX.tag DateTime.Now let don = UMX.tag (DateOnly.FromDateTime(DateTime.Now))