AttemptIt – An F# computation expression for Railway Oriented Programming

For a while now I’ve been advancing my F# knowledge in various ways, one of those ways was to create a computation expression. As well as that I also wanted to release a useful nuget package and to add more open source software to the world.

While learning F# I found this article on railway oriented programming which I found quite effective in my day to day development. Finding no existing code/nuget packages that already had this I decided to create me own.


The ReadMe file is vary basic for now but it should give you the general idea I’m trying for. Essentially an “attempt” represents a computation that is either a success or a failure; this can then be evaluated in to a “result”.

The syntax for now should let you bind from other attempts and bind from other results.

A quick reminder of the syntax:

//Basic usage
let doThis = attempt {
    let! x = someFunc()
    let! y = someOtherFunc y
    return! finalFunc y

//Catching Exceptions
let exceptionHandler (e:exn) -> Fail e.Message
let tryThis = Attempt.Catch exceptionHandler doThis

let result = Attempt.Run tryThis

The plans for the not so distant future are:

  • Add Async helpers (Async<Attempt<‘a,’b>> gets award to work with I find)
  • Extend the syntax (for, while etc)
  • Add customer operators (check out “doublemap” in the railway programming link)
  • Get Travis-CI building this
  • Add more tests

This is also my second publicly available F# project and any comments on the code would be grateful.

Leave a Reply