Datatype-generic programming is a powerful technique that allows you to parameterise your functions by the shape of the types that they are invoked with. A simple example of datatype-generic programming is a pretty-printer for arbitrary record types – it inspects the structure of the record type at runtime to find its fields and then prints the value of each field in turn.
In .NET languages, datatype-generic programming is typically achieved through a combination of generic type parameters and reflection, but this method suffers from the proliferation of obj values and therefore unsafe code.
In this talk, we’ll take a look at three libraries:
• TypeEquality - ahttps://github.com/G-Research/TypeEquality
• HCollections - ahttps://github.com/nickcowle/HCollections
• TeqCrate - ahttps://github.com/nickcowle/TeqCrate
We’ll show that when taken together, these libraries offer a type-safe abstraction layer over simple reflection. By using them, we can create our own libraries that are not only type-safe with respect to their public API, but whose internal implementations are completely type-safe as well.
YOU MAY ALSO LIKE:
- Lightning Talk: Existentials - Playing Hide and Seek With Your Types (SkillsCast recorded in April 2018)
- Functional Concurrency in .NET with C# and F# with Riccardo Terrell (Online Course on 1st - 4th December 2020)
- F# eXchange 2020 (Online Conference on 21st October 2020)
- Haskell eXchange 2020 (Online Conference on 4th - 5th November 2020)
- Build High Performance Stream Processing and Workflows with TPL Dataflow (SkillsCast recorded in October 2020)
- Applied Domain-Driven Design — Full-Stack Event Sourcing (SkillsCast recorded in July 2020)
Type-Safe Datatype-Generic Programming in F#
Professional F# developer by day, amateur type theorist by night, Nick enjoys drawing ideas from the world of functional programming to create robust and safe software for the finance industry.