r/functionalprogramming • u/GothicMutt • Feb 06 '24
Question Opinions on learning Ocaml vs F#?
As part of my senior level courses at my uni, I've had to learn a bit of Standard ML. I've been enjoying SML a lot, but from what I've read online, it seems that it's used mostly in universities for teaching/research and not too much else.
I'm really interested in sticking with the ML family and learning a language that could be more practically useful (both in terms of employment opportunities and in personal projects). More specifically, I'm interested things like in game development, graphics programming, low-level computing, embedded systems, etc.
In doing some of my own research, it seems as though either Ocaml or F# would be my best bet in terms of fulfilling those first two points, but I'm trying to figure out how to decide between the two thereafter.
Any advice/personal experience and insight would be greatly appreciated. Thanks!
2
u/amirrajan Feb 10 '24
If it helps, OCaml has SDL bindings (I haven’t tried it though): https://github.com/fccm/OCamlSDL2/blob/master/examples/ex_sprite.ml
Generally speaking, you’ll want to look for C libraries that you want to leverage and see if an OCaml foreign function interface exists for the library.
If you’re on a Windows machine, F# may be a better option. Any framework that is available to C# can be used with F#
2
u/zaywolfe Feb 13 '24
If you're interested in game and graphics programming you're much better off using functional techniques inside of c++. I've been through a few excursions in trying to use functional languages for game dev but I've always been left disappointed and discouraged in the end. With c++ you'll get clean interfaces with your graphics API of choice and have experience you can take with you that can be applied across the industry.
For some background I'm a technical artist by trade with my focus being shaders. A good ml language with a clean c interface like zig has and full windows support would have me singing in the streets.
4
u/burtgummer45 Feb 06 '24
sounds like a terrible choice for game development and low level computing. If you want to do those in a almost ML use rust
but if you want to do browser graphics and games there's https://rescript-lang.org/, but warning there is zero community for that, so you'd have to write the three.js bindings yourself (which isn't that big a deal)
18
u/fridofrido Feb 06 '24
F# is essentially a dialect of OCaml running on the dotnet platform. So skills should be mostly transferable, I guess.
(no personal experience, I'm a Haskell guy)
9
u/XDracam Feb 07 '24
I don't know OCaml, but I know F#. I recommend you learn OCaml first. Why?
4
u/gplgang Feb 07 '24 edited Feb 07 '24
I would go for F# because of the interest in game dev and graphics programming. There's a lot of good resources for using .NET with graphics and gamedev, while OCaml's ecosystem is a lot smaller than .NET
.NET also has easier C FFI than OCaml and support for structs which can come into play for working with lower level systems
As far as the two languages go they're pretty similar with OCaml having some extra FP features. For most domains like writing compilers or web servers I would say neither has a clear advantage
If you're looking for more advice on using F# feel free to PM me or join the F# discord
https://discord.gg/QqatymeA
Silk.NET will give you access to graphics APIs like OpenGL and WebGPU, Fable will allow you to compile F# to JavaScript and use libraries like threejs (I have a set of bindings available I can send you), and both Unity / Godot support .NET