F# vs OCaml: Image Processing
While asking on the OCaml mailing list about the relative merits of our HLVM project, David McClain described a computation that he had been required to perform in the context of scientific computing in the past: "I remember dealing with stacks of images taken from an infrared imaging sensor -- perhaps 256 images, each of which is, say 512 x 512 pixels. I needed to obtain median pixel values from the stack and produce one median image..." This problem is easily solved in both OCaml and F# using idiomatic functional programming. For example, the following is a one-line solution written in OCaml: Array.map (Array.map (fun gs -> Array.sort compare gs; gs.(m/2))) images This simply sorts each pixel's sequence into non-descending order and extracts the middle (median) pixel, mapped across the columns and then the rows of the image. This tiny implementation solves David's example with 2 26 pixels in 32 seconds, which is fast enough for many applications. However, the ...