Some Quick Thoughts on F#
F# is not my first functional language. I’m looking into it as a possible tool for future work at Atalasoft. Here are my thoughts so far after writing several hundred lines of F# over roughly two days:
- I’m writing in it like I write in Scheme, but with a heavy tail-recursive bent
- I don’t like the way currying creates partial function application by default. My most common error in writing F# so far is leaving off an argument to a function. I want an error, but F# gives me a curried function.
- I don’t like the property syntax – it’s as bad as C++/CLI – why make common tasks so painful? The obvious syntactic sugar should be “property this.PropertyName get = <body>”
- I don’t like the modularity/package grouping, but I need to read up on it.
One thing I wrote which I do like quite a bit is a glue function to handle possibly null arguments:
let RaiseOnNull obj (description:string) =
if obj = null then raise(ArgumentNullException(description)) else obj
which lets you write code using this pattern:
let Foo a b c =
let _a = RaiseOnNull a "a"
let _b = RaiseOnNull b "b"
let _c = RaiseOnNull c "c"
I know that F# wants you to not use null as values, but if you need to interface with the rest of .NET, this is a reality and this lets you handle it gracefully.