Welcome to Atalasoft Community Sign in | Help

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:

  1. I’m writing in it like I write in Scheme, but with a heavy tail-recursive bent
  2. 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.
  3. 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>”
  4. 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.
Published Friday, May 14, 2010 4:56 PM by Steve Hawley


Friday, May 14, 2010 9:42 PM by RickM

# re: Some Quick Thoughts on F#

Hi Steve,

You can stop currying if you can treat any function as a function of an input tuple.

let Foo (a,b,c) = ...

Can't be partially applied.  It won't create a tuple under the hood for that so it's nice and fast.

The property syntax is really to discourage mutable properties.  It's fewer lines of code than C# before { get; set; } at least.  I can see where you're coming from though.

Finally, check out this null checker.  You can check all of your parameters at once with this.

let RaiseOnAnyNull args =

 List.map (fun (obj,desc) ->

   if obj = null then nullArg desc) args

let Foo a b c =

 RaiseOnAnyNull [(a,"a"); (b,"b"); (c,"c")]

See you on monday,


Monday, May 17, 2010 10:49 PM by RickM

# re: Some Quick Thoughts on F#

Hi Steve,

I thought you would enjoy these Stream extensions.  


They might not be the fastest, but I think they could be optimized and make for REALLY small codecs.

Anonymous comments are disabled