ShapeSifter 1.1.2
See the version list below for details.
dotnet add package ShapeSifter --version 1.1.2
NuGet\Install-Package ShapeSifter -Version 1.1.2
<PackageReference Include="ShapeSifter" Version="1.1.2" />
paket add ShapeSifter --version 1.1.2
#r "nuget: ShapeSifter, 1.1.2"
// Install ShapeSifter as a Cake Addin #addin nuget:?package=ShapeSifter&version=1.1.2 // Install ShapeSifter as a Cake Tool #tool nuget:?package=ShapeSifter&version=1.1.2
ShapeSifter
Type-safe datatype-generic programming for F#.
Getting started
The most useful place to start is likely with the tType<'a>
function and corresponding active patterns in the Patterns
module.
These patterns reflectively determine what type 'a
was, and give you evidence in the form of a Teq
(see TypeEquality).
Where appropriate, you also get a type-safe representation of the type's structure.
Here is a brief example.
Everything written here was forced by the types: once we chose to match on the Unit
and Record
active patterns, there was only one way to write this function so that it compiled.
open ShapeSifter
open ShapeSifter.Patterns
let manipulateType<'a> () =
match tType<'a> with
| Unit teq ->
printfn "'a was a unit type, and `teq` witnesses this!"
| Record data ->
{ new RecordConvEvaluator<_> with
member _.Eval (fieldData : RecordTypeField list) (fieldTypes : TypeList<'ts>) (conv : Conv<'a, 'ts HList>) =
failwith "manipulate the type here"
}
|> data.Apply
| _ -> failwith "unrecognised type"
Inside the RecordConvEvaluator
, we have gained access to:
- The list
fieldData
of record fields, telling us the name of each field and any attributes that were on the field (as well as the rawPropertyInfo
associated with each field). - The same list of field types, but expressed as a
HeterogeneousCollections.TypeList
. - A
Conv
(converter) which lets us interchange between an'a
and a heterogeneous list of its field values.
We have now seen a pattern for a primitive type (Unit
) and for an arbitrary record.
Using the patterns in ShapeSifter, we can recognise the following types:
- Many primitive types, and
DateTime
andTimeSpan
Array<_>
,_ list
,Seq<_>
,Set<_>
Option<_>
Map<_, _>
_ * _
,_ * _ * _
, and arbitrary tuples_ -> _
Dictionary<_,_>
,ResizeArray<_>
Teq<_, _>
- Records and unions
- "Sums of products" (that is, unions, but where we give you easier access to the products which make up the union fields).
More examples
See the tests for examples demonstrating how to perform type-safe manipulation of various different types. There is a whistlestop tour and a specific example of type-safe CSV parsing.
Credits
This library was originally built by Nicholas Cowle.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- HeterogeneousCollections (>= 1.0.3)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.