ShapeSifter 1.1.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package ShapeSifter --version 1.1.1                
NuGet\Install-Package ShapeSifter -Version 1.1.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ShapeSifter" Version="1.1.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ShapeSifter --version 1.1.1                
#r "nuget: ShapeSifter, 1.1.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ShapeSifter as a Cake Addin
#addin nuget:?package=ShapeSifter&version=1.1.1

// Install ShapeSifter as a Cake Tool
#tool nuget:?package=ShapeSifter&version=1.1.1                

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 raw PropertyInfo 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 and TimeSpan
  • 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.1.9 77 10/22/2024
1.1.8 63 10/22/2024
1.1.7 95 10/9/2024
1.1.6 109 9/3/2024
1.1.5 108 9/3/2024
1.1.4 103 8/27/2024
1.1.3 116 8/20/2024
1.1.2 115 8/20/2024
1.1.1 117 8/20/2024
1.0.4 101 6/11/2024
1.0.3 107 6/4/2024
1.0.2 105 6/4/2024
1.0.1 127 5/30/2024