Skip to content

Instantly share code, notes, and snippets.

@latkin
latkin / extendAPIWithUnits.md
Last active March 31, 2016 21:39
How to extend a 3rd-party API with F# units of measure

Extending a 3rd-party API with F# units of measure

F# units of measure are nice, but what if I'm using a 3rd-party library which doesn't support UOM? I don't want to re-implement the library, but it would be nice to add the extra safety afforded by UOM. Can I somehow annotate the APIs of the 3rd party library with units?

Yes!

How to do it

Say you have some unit-free external library like this, which you can't modify:

@hanssens
hanssens / Pluralizer.cs
Created May 30, 2012 12:30
[C#] Pluralizer
/* **********************************************************************************
*
* Copyright (c) Microsoft Corporation. All rights reserved.
*
* This source code is subject to terms and conditions of the Microsoft Permissive
* License (MS-PL). A copy of the license can be found in the license.htm file
* included in this distribution.
*
* You must not remove this notice, or any other, from this software.
*