Tag Archives: OSS

F#

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.

AttemptIt

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

//Evaluating
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.

Code

My first OSS project – DOAP

At work I’m developing a web api for a project that is to be used be several devices and possibly by 3rd parties; I was having a discussion with a few colleagues about the best way to secure this api and this eventually moved on to OAuth.  The choice we faced was do we go with the existing and finalised OAuth protocol or do we take a chance and jump on board with OAuth 2 and all the benefits  it brings, the choice was easy we needed or api to work on mobile devices, desktop apps and a whole host of non-web based apps.

Next step was to see if there was an existing library that allowed us to be a provider. Two that came up (did I mention this was a .Net project?) were DotNetOpenAuth and another one which I’ve just forgotten. I played about with both attempting to get it up and running but had some difficulty. Neither library suited my needs so I decided to try and build one my self; and I did 🙂

I had a read through the PHP implementation and read the protocol draft several times over and what I developed is my  best interpretation of it. The project I was working on required the use of the assertion/password/refresh grants and that’s all I’ve tested so far. Hopefully someone will give the others a try too.

Source: http://github.com/TWith2Sugars/DOAP

License: MIT

Dependencies: WCFRestContrib (only for the WCF helper attributes)

WCF

The project I’m working on has the api provided via WCF and obviously I had to get my OAuth implementation working with WCF (With a huge help from the fantastic WCFRestContrib library). Check out the example in the github repo to see a working version.

Why DOAP?

DotNet OAuth Provider of course.


There is no binaries yet, not until the draft is finalised or someone requests it. It’s easy to build any way as there are barley any dependencies.

I’ll make a post of how to set it up soon but until then hopefully the example is enough to get you going.