Today I was speaking with a colleague about some F#, and he pointed out a few gotchas with F# type signatures, especially if you’ve spent some time with Haskell (and not OCaml or other ML-ish language).
F# gave me the following error when working with some C# code:
error FS0729: This field is not a literal and cannot be used in a pattern
I’m not entirely sure it’s a good idea, but I managed to work around this using a partial active pattern.
There are a few different libraries that provide test assertions for F#. I went through a couple today and tried a trivial example in each.
Every so often I want to quickly sketch out what should be a simple diagram. Irrespective of what drawing program I use, I always seem to take much more time than I intend for a result that does not even remotely resemble what I want.
So I decided to give up and find a way to use hand-drawn sketches instead. Here’s the method I ended up with, based almost entirely on Marc Liberatore’s "Whiteboard Diagrams as PDFs" post and the wonderful ImageMagick and Potrace utilities.
My drawings still look fairly terrible, but at least they convey what I want them to and are quick to produce! :)
Apparently it can be a bit tricky to get some Haskell libraries working on Windows, in which case the Haskell Platform is a great way to get going with Haskell. For Mac and Linux the platform works too, but we can also just grab the latest GHC and Cabal (ooh, shiny!) and go from there.
tl;dr: Make invalid regular expression strings and attempts to access non-existent capture groups a compile-time error, thanks to the Regex type provider.
Either type, also called
Choice in F# parlance, is a way of representing a value that can be either one of two types. This can be extremely useful. For example, retrieving a date of birth from a textbox could be expressed as
Either<ParseException, DateTime>. In other words, the result is a value that is either a valid
DateTime, or is a
Being a hasty introduction this post is not going to do justice to how useful this type is, but hopefully some of its goodness will shine through despite my rambling prose. :)