Snippets created by Tim Robinson

  • Exiting cleanly

    Demonstrates how to run a function when the user presses Ctrl+C, closes the console window, or logs off.

    31 people like this

    Posted: 6 years ago by Tim Robinson

  • Member constraints on records

    Demonstrates explicit member syntax as applied to record fields

    29 people like this

    Posted: 6 years ago by Tim Robinson

  • Type-safe URL templates for Nancy

    The Nancy web framework parses URLs for you, and passes requests under a given URL route and HTTP method to your program. It relies heavily on C# dynamic objects; these don't translate well in F# code, and it's easy to make mistakes that only show up at run time. Here we define one F# record type for each route, with an attribute that defines the URL, with placeholders for each field in the record. These types implement one generic interface for each HTTP method they support: for GET, PUT and POST, these generic interfaces also specify the types of the HTTP request and response bodies.

    5 people like this

    Posted: 4 years ago by Tim Robinson

  • Observable.computed

    Knockout (http://knockoutjs.com) provides observable primitives similar to IObservable in Rx. Knockout also has ko.computed, which abstracts away individual subscriptions: you write a function that references the current values of observables, and it takes care of the rest. Here is ko.computed in F#.

    2 people like this

    Posted: 3 years ago by Tim Robinson

  • Byte literals

    Demonstrates an array initialized from byte literals, which use the 'uy' suffix, and an array initialized from a string byte array literal

    46 people like this

    Posted: 6 years ago by Tim Robinson

  • MD5 hash

    A function that computes an MD5 hash from a block of bytes. MD5 isn't cryptographically secure, but it's a handy way of condensing a block of data into a short string.

    19 people like this

    Posted: 6 years ago by Tim Robinson

  • .NET 1.1 collections in F#

    Even with the latest tools, we're sometimes exposed to .NET archeaology: parts of the framework designed before .NET 2. Examples of this are the dictionary classes from System.Collections, which are a little strongly typed, but not quite -- you see them if you call HttpUtility.ParseQueryString, or if you use pretty much anything in System.Configuration. Here's some code to make these classes a little safer in F#.

    3 people like this

    Posted: 3 years ago by Tim Robinson