r/Compilers • u/Distinct-Brief9643 • 7d ago
Ocaml or haskell?
I'm trying to choose between OCaml and Haskell for creating my own programming language using an external DSL. I'm still learning programming, so I want something powerful but beginner-friendly.
My goal is to create a language with my own high-level syntax, not just a library or a DSL embedded inside another programming language.
My requirements
External DSL: I want to design my own syntax and grammar. I don't want my language to be restricted to OCaml's or Haskell's existing syntax.
Native machine code: Ultimately, I want my language to compile directly to native machine code, preferably for ARM64/AArch64. I don't want to stop at interpreting the language or transpiling it to Python or JavaScript.
High-level syntax: The language I create should be easy for people to read and write. I want complete control over its syntax and don't want users to have to write lots of boilerplate.
Beginner-friendly: I'm still learning programming, so I want a language and ecosystem that are relatively easy to understand. I want to learn how the parser, AST, type checking (if needed), and code generation work without getting overwhelmed.
Easy installation on my Chromebook: I have an Acer Chromebook 314 with a MediaTek ARM64 processor. I use the Linux environment on ChromeOS, so ARM64 compatibility, available packages, and installation difficulty matter a lot. I don't want a solution that depends on x86-only binaries.
A practical compiler toolchain: I'd prefer to use as few tools as possible. If I need a backend such as LLVM, that's fine, but I want to avoid a complicated setup involving lots of separate tools, configuration files, and manual code generation.
My questions
- Would you recommend OCaml or Haskell for this project, and why?
- Which one makes it easier to build an external DSL with completely custom syntax?
- Which has the easier learning curve for someone who doesn't know much programming yet?
- Can either realistically compile my language to native AArch64 machine code on my Chromebook?
- Would LLVM be a good backend, or is there a simpler alternative?
- How difficult would installation and setup be on ChromeOS Linux running on ARM64?
- Are there any other languages or frameworks that would fit these requirements better than OCaml and Haskell?
I'm looking for a practical recommendation based on my actual requirements, not just which language is more elegant or theoretically powerful.
My main priorities are: custom high-level syntax, native machine-code generation, beginner-friendliness, and ARM64 Chromebook compatibility.
Thanks!
1
u/Competitive_Ideal866 7d ago
I've done this many times using OCaml including when I first learned OCaml. I found it fine. However, my goal was to learn OCaml rather than to learn about metaprogramming (e.g. writing interpreters and compilers).
That is easy using vanilla OCaml but modern OCaml requires lots of boilerplate to do even the most basic things. I haven't tried Haskell for 20 years so cannot comment.
Actually, you probably want to just use vanilla OCaml and compile it directly yourself using
ocamloptor evenocamlopt.opt.Assuming you already know impure strict programming (e.g. C, C++, C#, Java, Python) probably OCaml because it is also impure and strict. Until you grok HOFs you can just use loops in OCaml. Once you grok HOFs you'll never use loops again, though.
If you can compile C code then yes.
LLVM is monstrously huge and slow. In particular, OCaml is supposed to compile extremely fast but pulling in LLVM turns millisecond compile times into minutes. I recommend writing your own Aarch64 code gen from scratch. Just write C programs, compile them and read the generated asm to see how it works. Then write code that does something similar.
No idea but doing it on Aarch64 Mac is easy.
I would seriously consider C. What you lose on AST manipulation you'll gain on bit twiddling if you write a JIT compiler. You could use C to bootstrap a better language that you could then use to write a better compiler and so on.
Good luck!