5 comments

[ 0.21 ms ] story [ 22.2 ms ] thread
Took me a moment to realise the code is so weird because he's doing this in AutoCAD. My brain blocked out most of the site and went straight to the middle of the code.
I've read like 10 entries on that blog, that guy knows how to do some stuff.
Notice how C# requires 16 type annotations, whereas F# only needed 1.

The verbosity of the F# example is not necesary. For instance, the code does its own map:

  let rec fromAtoBs acc pt1 pts =
    match pts with
    | [] -> acc
    | pt2::t ->
      let ln = new Line(pt1,pt2)
      fromAtoBs (ln :: acc) pt1 t

  let linesFromPoint start endpts = fromAtoBs [] start endpts
Instead of just:

  let linesFromPoint start endpts = 
      endpts |> List.map(fun x -> Line(start, x)) 
             |> List.rev
It's like he read the first few chapters of an F# book which showed explicit recursion for didactic purposes and then stopped before the examples explained higher-order functions.
Most of the type definitions could have been replaced by "var".