Good day all,
I am developing a small hobby project in OCaml. I was wondering how easy it would be to migrate it to F#. I know that F# has some features that OCaml doesn't, but I was hoping that my OCaml code would require little effort to port. I don't necessarily want to migrate, I want to retain / develop on both platforms.
Thanks in advance, Michael
OCaml is statically typed where there is no need of writing explicit type declaration as the compiler will intimate your types. F# is a strongly typed functional language that uses type inference which means this also does not need a declaration of the type and this is done by the compiler.
Let's start with the obvious, F# is OCaml. It's OCaml backed by the world's largest and most experienced creators of programming languages. And in the areas that OCaml is great, F# is also great! Sum types, static typing, eager execution, pipelines, immutable values, all of this is really great.
Writing cross-compiling code looks like a world of pain to me. John Whitington of Coherent PDF is the only person I know of who has tried to do this to any real degree.
I have translated a lot of OCaml code to F# (probably more than anyone else in the world) and the main problems are #light
syntax, the use of any non-trivial OCaml features (objects, polymorphic variants, higher-order modules, labelled and optional arguments and so on), libraries (e.g. lablgl, lablgtk, ocamlgraph, laziness), macros (parsing, streams, pattern matching extensions) and changes in basic syntax such as array indexing. For example, I just tried to port the Almabench benchmark from OCaml to F# and it took several hours because I ended up by having to rewrite every a.[i]
to an a.(i)
by hand due to a multitude of bugs in the F# compiler: its OCaml compatibility mode is quite fragile.
So I would advise you to choose between the languages rather than trying to cross-compile.
You should read the final portion of the spec
Features for ML Compatibility
and be sure to grab FSharp.PowerPack.Compatibility.dll from the PowerPack for various compat libraries.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With