r/ocaml

▲ 14 r/ocaml+1 crossposts

Ocaml newbie - some trouble with HPLAR

Please allow me to introduce myself, I am a man of the typeless world, mainly Racket, Clojure, that sort of thing. I've been meaning to get into the typed language scene for programming language exploration, and I was a bit torn between the apparent purity of Haskell and practicality of Ocaml.

My experience level is zero, as in I've never written a single line.

In the end, what decided it for me was that I wanted to work through Harrison's "Handbook of Logic Programming and Automated Reasoning" which is supported by Ocaml code. I am also interested in some other programming paradigms (cclp), where Ocaml seems to be mentioned more than Haskell.

Anyways, I installed Ocaml according to the Cornell 3110 instructions, both for utop and VSCode, seems fine, gives me the 5.3.0 compiler environment.

My problem is that when I try to set up the supplied code for HPLAR, cd-ing into the provided directory and trying #use "init.ml" on the indicated file, all sorts of weirdnesses appear. In VSCode I can't even enter the #use line without a syntax error! Never mind, I tried from utop and from plain vanilla CLI, where I get this:

# #use "init.ml";;
Cannot find file nums.cma.
File "init.ml", line 10, characters 6-27:
10 | then (Topdirs.dir_directory "+camlp5";
           ^^^^^^^^^^^^^^^^^^^^^
Error: Unbound module Topdirs

The init.ml fike is as follows:

aaa#load "nums.cma";;                            (* For Ocaml 3.06     *)

if let v = String.sub Sys.ocaml_version 0 4 in v >= "3.10"
then (Topdirs.dir_directory "+camlp5";
      Topdirs.dir_load Format.std_formatter "camlp5o.cma")
else (Topdirs.dir_load Format.std_formatter "camlp4o.cma");;

type dummy_interactive = START_INTERACTIVE | END_INTERACTIVE;;
#use "initialization.ml";;
#use "Quotexpander.ml";;
#use "atp_interactive.ml";;

So I am left wondering if the problems are due to the older compiler version supported here, two major releases are enough time for things to change quite a bit.

I am keen to get up to speed and start on the book as soon as possible, and even though some may say - well, learn the operational basics first and then sort it out yourself (fair enough), if there is anyone who can provide some help to get this going a bit quicker, I would appreciate it very much! Many thanks.

reddit.com
u/Dazzling_Music_2411 — 3 days ago
▲ 35 r/ocaml

Who is ocaml for?

Context: I am econ master's student with some experience in python, C and R looking to get into financial econometrics/ML. Is OCaml right for me?

reddit.com
u/I_am_Noro04 — 6 days ago
▲ 18 r/ocaml

codemod CLI in OCaml 5, vendored tree-sitter, Domainslib + Incremental

Built a pattern-rewriting CLI for TS / TSX / Python / Go / Rust.

Write console.log($X) and it matches by AST. Add --where '$X: string' and it filters using real type info from the language's LSP.

OCaml side:

  • vendored tree-sitter v0.25.6 + 5 grammars in dune so Homebrew ships a single static binary
  • Domainslib for parallel scans (~0.4s on 7k TS files)
  • Jane Street Incremental for watch mode with sub-ms re-runs after single-file edits
  • LSP client is just yojson + Unix.create_process, no external library

Repo: https://github.com/aryabyte21/morph

opam pin works. Requires OCaml 5.3+.

Happy to dig into any of the parser / incremental / build-system choices.

u/aryabyte — 12 days ago