Types + Properties = Software

Download this episode

Download Video

Description

Given a sufficiently strong type system, you can model your problem domain in such a way that invalid states become unrepresentable. This is one of the corner stones of encapsulation, but requires a lot of effort in mainstream object-oriented languages. In functional languages like F# and Haskell, on the other hand, this is possible using a purely declarative approach to types.
Once your types can guarantee that only valid states are representable, Property-Based Testing becomes a breeze.

In this talk, we'll look at using the powerful combination of F# types and properties to address an example problem.

Day:

1

Embed

Format

Available formats for this video:

Actual format may change based on video formats available and browser capability.

    The Discussion

    • User profile image
      Tomas

      Hello there, the conf is just awesome!

      I like the data structures like this that does not allow to represent an illegal state. Is there a straightforward way to expose such data structure to C# code?

      What is more common/correct scenario? To force the C# user of the F# library to instantiate the F# data structure? Or to provide "standard" class and covert it to discriminated union internally in the library?

      Thank you for great talk!
      Tomas

    • User profile image
      Matt Freeman

      Great example, I wish I had heard about the tennis kata earlier, I think it's a perfect example to demonstrate benefits of f# or ocaml.

    • User profile image
      ploeh

      @Tomas: You easily can't translate this technique to C#, because it relies on discriminated unions to give you another axis of variability in how you statically express the value space of a type. This leads into what's called algebraic data types, Here's an easy-to-read introduction: http://tomasp.net/blog/types-and-math.aspx

      Discriminated unions are usable from C#, but a bit awkward. In order to harvest the full benefits of F#, it's best to stay within F#.

    Comments closed

    Comments have been closed since this content was published more than 30 days ago, but if you'd like to send us feedback you canĀ Contact Us.