Grilled Cheese

ExploreLog inSign up
Terms of UsePrivacy PolicyCommunity StandardsHelpGet the app

Grilled Cheese is a product of Village Compute

Version devBuilt at: 2026-12-03 22:42:33 EST

PhotosVideosAllPeople
LatestRanked
Load more
?Unknown authorDec 5, 2026, 7:00 AM

🎄 #AdventOfCode day 5

This was easier than yesterday for me. Parsing was a breeze thanks to 🐫 #OCaml lexer.

I spent a few minutes 🤔 wondering why my code for part 2 didn't give the right result before realizing that I was running it on the sample rather than on my actual input… 😅

{
  type buttons = App of int | Mul of int | Div of int | Swp of char * string | Oct | Del
  let press screen = function
    | App d -> screen * 10 + d
    | Mul d -> screen * d
    | Div d -> screen / d
    | Swp (a, b) -> int_of_string String.(concat b (split_on_char a (string_of_int screen)))
    | Oct -> int_of_string (Printf.sprintf "%o" screen)
    | Del -> screen / 10
}

let digit = ['0' - '9']

rule buttons = parse
| eof { [] }
| ' ' | '\n' { buttons lexbuf }
| "[" (digit as d) "]" { App (int_of_char d - int_of_char '0') :: buttons lexbuf }
| "[*" (digit as d) "]" { Mul (int_of_char d - int_of_char '0') :: buttons lexbuf }
| "[/" (digit as d) "]" { Div (int_of_char d - int_of_char '0') :: buttons lexbuf }
| "[" (digit as a) "->" (digit as b) "]" { Swp (a, String.make 1 b) :: buttons lexbuf }
| "[oct]" { Oct :: buttons lexbuf }
| "[bksp]" { Del :: buttons lexbuf }

{
  let buttons = buttons (Lexing.from_channel stdin) in
  let smash screen = List.map (press screen) buttons in
  let screens =
    let rec loop n screens =
      if n = 0 then screens else
      loop (n - 1) List.(map smash screens |> concat |> sort_uniq Stdlib.compare)
    in loop 3 [0]
  in
  Printf.printf "%d\n" (List.fold_left (+) 0 screens)
}
{
  type buttons = App of int | Mul of int | Div of int | Swp of char * string | Oct | Del
  let press screen = function
    | App d -> screen * 10 + d
    | Mul d -> screen * d
    | Div d -> screen / d
    | Swp (a, b) -> int_of_string String.(concat b (split_on_char a (string_of_int screen)))
    | Oct -> int_of_string (Printf.sprintf "%o" screen)
    | Del -> screen / 10
}

let digit = ['0' - '9']

rule buttons = parse
| eof { [] }
| ' ' | '\n' { buttons lexbuf }
| "[" (digit as d) "]" { App (int_of_char d - int_of_char '0') :: buttons lexbuf }
| "[*" (digit as d) "]" { Mul (int_of_char d - int_of_char '0') :: buttons lexbuf }
| "[/" (digit as d) "]" { Div (int_of_char d - int_of_char '0') :: buttons lexbuf }
| "[" (digit as a) "->" (digit as b) "]" { Swp (a, String.make 1 b) :: buttons lexbuf }
| "[oct]" { Oct :: buttons lexbuf }
| "[bksp]" { Del :: buttons lexbuf }

{
  let buttons = buttons (Lexing.from_channel stdin) in
  let smash screen = List.map (press screen) buttons |> List.filter ((>) 10000) in
  let module S = Set.Make(Int) in
  let screens =
    let rec loop screens =
      let screens' = S.fold (fun s s' -> S.add_seq (List.to_seq (smash s)) s') screens screens in
      if S.(cardinal screens' = cardinal screens) then screens
      else loop screens'
    in loop (S.singleton 0)
  in
  Printf.printf "%d\n" (S.fold (+) screens 0)
}
?Unknown authorDec 5, 2026, 6:35 AM

OCaml: Learn & Code is a developer tool (GPL-3.0). OCaml editor with a growing learn section.

https://apps.apple.com/app/ocaml-learn-code/id1547506826

#opensource #developer #ocaml

Photo, no description
?Unknown authorDec 4, 2026, 7:23 PM

🎄 #AdventOfCode day 4

This one was a bit scarier at first, but it was a lot of fun in the end.

Here is my 🐫 #OCaml solution, and then another more elegant one (although a bit less efficient) inspired by the approach of a colleague.

let rec set l i v =
  if i = 0 then v :: List.tl l
  else List.hd l :: set (List.tl l) (i - 1) v

let rec patlen bc =
  let s = String.(trim (replace_all ~sub:"?" ~by:" " bc)) in
  let len = String.length s in
  if len < 2 then 1 else
  let lst = List.of_seq (String.to_seq s) in
  let rec checklen n =
    if n = len then n else
    let rec checkpat pat =
      let rec check i p l =
        match p, l with
        | _, [] -> n
        | [], l -> check 0 pat l
        | x :: p, c :: l when c = ' ' || c = x -> check (i + 1) p l
        | ' ' :: _, c :: _ -> checkpat (set pat i c)
        | _ -> checklen (n + 1)
      in check 0 pat lst
    in checkpat (List.take n lst)
  in checklen 1

let () =
  let barcodes = In_channel.input_lines stdin in
  Printf.printf "%d\n%d\n"
    List.(map patlen barcodes |> fold_left (+) 0)
    (String.concat "" barcodes |> patlen)
let rec single = function
  | [] -> true
  | x :: y :: _ when x <> y -> false
  | _ :: l -> single l

let minarg f = let rec loop n = if f n then n else loop (n+1) in loop 1

let foldable bc n =
  let l = String.length bc in
  let rec sub i =
    if i >= l then [] else
    if bc.[i] <> '?' then bc.[i] :: sub (i+n) else sub (i+n)
  in List.for_all single (List.init n sub)

let () =
  let barcodes = In_channel.input_lines stdin in
  Printf.printf "%d\n%d\n"
    List.(map (fun bc -> minarg (foldable bc)) barcodes |> fold_left (+) 0)
    (minarg (foldable (String.concat "" barcodes)))
@xvw.lolDec 4, 2026, 9:06 AM

Wax: A User-Friendly Syntax for WebAssembly

"a #Rust-like syntax for #WebAssembly that compiles to exactly the same instructions. It comes with a toolchain, written in #OCaml, that converts between Wax and WebAssembly's text and binary formats in every direction."

lobste.rs/s/qdmolf/wax...

lobste.rsWax: A User-Friendly Syntax for WebAssembly2 comments
@lomig.bzhDec 3, 2026, 2:36 PM

And using #TypeScript too, of course, because "it's essential for frontend development", as if LLMs couldn't help us move to another language that can easily be transpiled to #JavaScript.

For example one of the few languages that can do this both easily and perfectly...

Oh. Right.

#OCaml.

@lomig.bzhDec 3, 2026, 2:36 PM

Finally, #OCaml.

OCaml is actually perfect for LLMs. It's highly expressive (less so than Ruby, but arguably as much as or more than Python), can be used for quick scripts and interactive experimentation, while also offering highly performant native compilation.

?Unknown authorDec 3, 2026, 7:59 AM

🎄 #AdventOfCode day 3

It's grid time already! It was fun to solve it in a purely functional way using 🐫 #OCaml ☺️.

I really like that the code for part 2 can be adapted to solve part 1 by removing a *single* character in it.

{
  module T = Set.Make(struct type t = int * int let compare = compare end)
}

rule map trees i j = parse
| '#' { map (T.add (i, j) trees) i (j+1) lexbuf }
| '.' { map trees i (j+1) lexbuf }
| '\n' { map trees (i+1) 0 lexbuf }
| eof { trees }

{
  let ts = map T.empty 0 0 (Lexing.from_channel stdin) in
  let to_check (i, j) = T.(filter (fun (i', j') -> i' <= i && j' > j) ts |> to_list) in
  let is_square (i, j) (i', j') = T.(mem (i+j'-j, j-i'+i) ts && mem (i'+j'-j, j'-i'+i) ts) in
  let (+^) n b = n + Bool.to_int b in
  let count_squares t = List.(map (is_square t) (to_check t) |> fold_left (+^) 0) in
  Printf.printf "%d\n" List.(map count_squares (T.elements ts) |> fold_left (+) 0)
}
?Unknown authorDec 2, 2026, 10:25 AM

🎄 #AdventOfCode day 2

Using 🐫 #OCaml, Part 1 was easily done in one pass on the file using ocamllex, and I reused it as is for part 2 after a tiny bit of wrangling on the input, so it's just a line of #Bash that pipes into part 1.

{
  let color = String.index "roygbv"
  let steps c i = match ((color i) - (color c) + 6) mod 6 with 0 -> 6 | d -> d
}

rule move dist cur = parse
| eof | '\n' { dist }
| _ as instr { move (dist + steps cur instr) instr lexbuf }

{
  Printf.printf "%d\n" (move 0 'r' (Lexing.from_channel stdin))
}
cat | tr "rvbgyo" "abcdef" | fold -w 1 | sort | tr "abcdef" "rvbgyo" | tr -d "\n" > tmp
../../aoc.sh run part1.mll tmp
rm tmp
?Unknown authorDec 1, 2026, 2:44 PM

🎄 #AdventOfCode day 1

I like using ocamllex to read the input but here it was really useless because the parsing is trivial so I made a pure #OCaml version :

let sorted = In_channel.input_lines stdin |> List.map int_of_string
  |> List.sort compare |> List.fold_left
    (fun acc id ->
      match acc with
      | (pre, c) :: r when id = pre -> (id, c+1) :: r
      | r -> (id, 1) :: r) []
  |> List.sort (fun (_, c) (_, c') -> compare c' c)
  |> List.map fst

let () =
  Printf.printf "%d\n%d\n"
    List.(sorted |> take 3 |> fold_left ( * ) 1)
    List.(rev sorted |> take 3 |> fold_left ( * ) 1)
@sibylresearch.bsky.socialDec 1, 2026, 2:00 PM

"In order to be competitive you actually have to turn around a packet in under 100 nanoseconds." Ron Minsky, Jane Street's co-head of technology, in a May 2026 conversation with Dwarkesh Patel posted on Jane Street's channel (Jane Street sponsors Patel's podcast).

#JaneStreet #OCaml

@dinosaure.mastodon.social.ap.brid.gyDec 1, 2026, 11:17 AM

If you want to learn about #unikernels in #OCaml and how to develop them and also how to deploy/use them, I will do a tutorial (like uniker.nl) at the next #BOBKonf 2027 (and you can also see two talks from two great Xaviers). See the program here: bobkonf.de/2027/en/prog…

uniker.nlHome — Unikernels in OCamlBuilding operating systems that do one thing with OCaml and Solo5.
?Unknown authorDec 1, 2026, 5:54 AM

🎄 #AdventOfCode day 1 ! Oh oh oh !

I did this one using #Bash one-liners first but still implemented it as usual in 🐫 #OCaml (and ocamllex) too, for the fun of it :).

Bash: echo $(($(cat | sort | uniq -c | sort -nr | head -3 | rev | cut -d' ' -f1 | rev | tr '\n' '*')1))

OCaml :

rule ids = parse
| ['0' - '9']+ as id { int_of_string id :: ids lexbuf }
| '\n' { ids lexbuf }
| eof { [] }

{
  ids (Lexing.from_channel stdin)
  |> List.sort compare
  |> List.fold_left (fun acc id ->
    match acc with
    | (pre, c) :: r when id = pre -> (id, c+1) :: r
    | r -> (id, 1) :: r) []
  |> List.sort (fun (_, c) (_, c') -> compare c c')
  |> List.take 3
  |> List.map fst
  |> List.fold_left ( * ) 1
  |> Printf.printf "%d\n"
}
@lwflouisa.comics.town.ap.brid.gyNov 29, 2026, 3:18 AM

Maybe for non lisp tasks I might do #ada and #ocaml sense that seems to be direction my own language is heading.

@dinosaure.mastodon.social.ap.brid.gyNov 25, 2026, 10:57 AM

On peut même avoir un tel service sous la forme d'un #unikernel en #OCaml. Le mien est disponible ici: paste.osau.re/ et un autre disponible ici: pasteur.khal1d.com/. Le projet est développé ici: github.com/dinosaure/pa…. On y décrit le build et le déploiement. Pas de PHP, pas de shell, même pas […]

mastodon.socialOriginal post on mastodon.social
@gazagnaire.orgNov 23, 2026, 1:43 PM

How do you stress tests an operating system without touching the hardware: gazagnaire.org/blog/2026-11...

#ocaml

gazagnaire.orgThomas Gazagnaire :: Chaos engineering as a libraryTesting what a program does when the power goes out or the network drops, from an ordinary unit test that hands it a simulated disk and network.
@dinosaure.mastodon.social.ap.brid.gyNov 20, 2026, 10:33 AM

I just write an article about our Chaos #unikernel, a simple NTP server in #OCaml. Now, you can use it via *.fr.pool.ntp.org. blog.robur.coop/articles/202…

DDinosaure@dinosaure.mastodon.social.ap.brid.gyNov 19, 2026, 5:10 PM

It's ALIVE: www.ntppool.org/scores/163.1… (#OCaml, #unikernel, #ntp)

ntppool.orgpool.ntp.org: Statistics for 163.172.65.89
@dinosaure.mastodon.social.ap.brid.gyNov 19, 2026, 5:10 PM

It's ALIVE: www.ntppool.org/scores/163.1… ( #OCaml, #unikernel, #ntp)

ntppool.orgpool.ntp.org: Statistics for 163.172.65.89
@jalonso.eurosky.socialNov 5, 2026, 7:04 PM

Verified purely functional catenable real-time deques. ~ Jules Viennot, Arthur Wendling, Armaël Guéneau, François Pottier.

arxiv.org/abs/2505.07681

#RocqProver #OCaml

arxiv.orgVerified Purely Functional Catenable Real-Time DequesWe present OCaml and Rocq implementations of Kaplan and Tarjan's purely functional, real-time catenable deques. The correctness of our Rocq code is machine-checked.
@batsov.netNov 5, 2026, 2:19 PM

Neocaml (a suite of #Emacs major modes for #OCaml development) 0.11 is out with #OxCaml support, multiple indentation styles (e.g. ocp-indent, conventional and janestreet), and many other improvements!

Read all about them here batsov.com/articles/202...

Feedback welcome!

batsov.comNeocaml 0.11: OxCaml, Indentation Styles, and odocI’m happy to announce that neocaml 0.11 is out! I never got around to writing about 0.10, which was mostly about neocaml-utop (a utop backend that talks to utop via its native editor protocol), but 0....
@tsmc.purely-functional.comNov 5, 2026, 2:35 AM

As a non-Windows person setting up OCaml on Windows is surprisingly straightforward with opam 2.6.1. Nice work on the Windows support opam devs! #ocaml