F# interface inheritance failure due to unit

This looks like a nasty corner-case in the F# language, but I’m not sure if it qualifies as a by-design limitation or a bug in the compiler. If it is by design limitation, then the error message should say that (because currently, it doesn’t make much sense). Anyway, the problem is that the F# compiler … Read more

F# changes to OCaml [closed]

This question has been answered for some time now, but I was quite surprised that most of the answers say what OCaml features are missing in F# – this is definitely good to know if you want to port existing OCaml programs to F# (which is probably the motivation of most of the referenced articles). … Read more

Help me to explain the F# Matrix transpose function

The function is not particularly readably written, which may be the reason for your confusion. The construct (_::_)::_ is a pattern matching on value of type list of lists of ints that says that the first case should be run when you get a non-empty list of non-empty lists. The same thing can be written … Read more

While or Tail Recursion in F#, what to use when?

The best answer is ‘neither’. 🙂 There’s some ugliness associated with both while loops and tail recursion. While loops require mutability and effects, and though I have nothing against using these in moderation, especially when encapsulated in the context of a local function, you do sometimes feel like you’re cluttering/uglifying your program when you start … Read more

F# getting a list of random numbers

Your code is simply getting one random number and using it ten times. This extension method might be useful: type System.Random with /// Generates an infinite sequence of random numbers within the given range. member this.GetValues(minValue, maxValue) = Seq.initInfinite (fun _ -> this.Next(minValue, maxValue)) Then you can use it like this: let r = System.Random() … Read more

Correct version of Fsharp.Core

You should not be obtaining FSharp.Core from nuget. Microsoft does not publish any official F# bits to nuget today (though this could potentially change in the future). It’s common for 3rd-party packages to bundle FSharp.Core (since presumably that’s the version used for testing/validation of that 3rd-party component), but nuget should not currently be used as … Read more

F#: let mutable vs. ref

I can only support what gradbot said – when I need mutation, I prefer let mutable. Regarding the implementation and differences between the two – ref cells are essentially implemented by a very simple record that contains a mutable record field. You could write them easily yourself: type ref<‘T> = // ‘ { mutable value … Read more