Nov 2017 — Jan 2023
Rationale
A Ramda-inspired functional utility library for ReasonML/OCaml — exception-free list operations, monadic Option and Result, FP ADTs (Reader, Writer, IO), point-free helpers, and lenses. My most-starred open-source project.
- ReasonML
- OCaml
- BuckleScript
What it is
Rationale is a collection of functional-programming utilities for
ReasonML / OCaml, inspired by
Ramda. Back in 2017 I was writing a lot of Reason, and
the standard library had gaps — and worse, a lot of its list operations threw
exceptions. Rationale filled in the missing pieces the way a Haskeller would want
them: total functions, options instead of exceptions, and real monadic
structure.
It’s the open-source project I’m proudest of. It picked up 275 stars and a handful of contributors — the most traction any of my repos has had. It’s old and unmaintained now, but people actually used it, and that still means a lot.
What’s in it
- Exception-free list operations —
head,tail,init,last,nthand friends returnoptioninstead of throwing, so partial functions become total. - Monadic
OptionandBelt.Result— Haskell-style functor/monad operators (<$>,>>=, …) for chaining fallible computations without a pyramid of pattern matches. - Functional ADTs —
Reader,Writer, and anIO/KIOmonad.KIOcarries an environment (io('a, 'env)), so you get dependency injection and isolated side effects, run once at the edge of your program. - Point-free style —
compose/pipeplus infix operators (<||,||>), and lens composition for reaching into nested data.
Here’s the flavor — a fallible list transformation expressed as a clean monadic pipeline instead of nested matches:
open Rationale.Option.Infix;
open Rationale.Function;
RList.init(a)
>>= (x => RList.last(a) <$> f <$> flip(RList.append, x))
<$> RList.concat(b)
|> Option.default(xs);
Why it still matters to me
Rationale is where my functional-programming instincts first showed up in public. The same things I cared about here — totality, isolating effects, composing small typed pieces — are exactly what pulled me toward Effect.ts and, eventually, to building Stax years later. Different language, same values.
Links
- Source: github.com/jonlaing/rationale