Skip to content

Add UOM for all basic types. #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Choc13
Copy link

@Choc13 Choc13 commented Aug 2, 2023

Based on #28 and the desire to support UOM for uint32 I've added UOM for all missing basic CLR types (except nativeint and unativeint).

[<MeasureAnnotatedAbbreviation>] type string<[<Measure>] 'm> = string
[<MeasureAnnotatedAbbreviation>] type TimeSpan<[<Measure>] 'm> = TimeSpan
[<MeasureAnnotatedAbbreviation>] type DateTime<[<Measure>] 'm> = DateTime
[<MeasureAnnotatedAbbreviation>] type DateTimeOffset<[<Measure>] 'm> = DateTimeOffset
#if NET6_0_OR_GREATER
[<MeasureAnnotatedAbbreviation>] type DateOnly<[<Measure>] 'm> = DateOnly
[<MeasureAnnotatedAbbreviation>] type TimeOnly<[<Measure>] 'm> = TimeOnly
#else
[<MeasureAnnotatedAbbreviation>] type uint32<[<Measure>] 'm> = uint32
Copy link
Author

@Choc13 Choc13 Aug 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the uint alias and the ability to support for UOM in FSharp.Core wasn't added until around F# 5. To work around this I think we need to use conditional compilation to add support for uint32 prior to this point in time hence the #else in the preprocessor directive.

I feel like this might not be the most accurate preprocessor directive to use though. So if anyone knows of a more F# language version specific one that we could use please let me know. I kinda wanted to use FSHARP5_OR_GREATER but couldn't find a reference for any commonly defined F# specific directives.

@@ -28,6 +28,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="FSharp.Core" Version="4.3.4" />
<PackageReference Condition=" '$(TargetFramework)' == 'netstandard2.0' " Include="FSharp.Core" Version="4.3.4" />
<PackageReference Condition=" '$(TargetFramework)' == 'net6.0' " Include="FSharp.Core" Version="6.0.7" />
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to target a newer version of FSharp.Core to pick up the uint alias. Again, I chose to do this when compiling for net6.0 as it felt like it was then safe to assume we could use this later version. If that's not acceptable or if there's a better condition to target than just net6.0 let me know.

@Choc13 Choc13 force-pushed the uom-all-basic-types branch 6 times, most recently from eb61d74 to 896598c Compare August 2, 2023 09:53
@Choc13 Choc13 force-pushed the uom-all-basic-types branch from 896598c to 89b68a5 Compare August 2, 2023 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant