What is the different between {} and <> with respect to records?


#1

There are two different syntaxes to declare types/interfaces

(* Syntax 1 *)
type person = {
  name: string;
  age: int;
  job: string;
}

(* Syntax 2 *)
type person = <
  name: string;
  age: int;
  job: string
>

Is it nominal vs structural typing? If yes, does OCaml/ReasonML support both?


#2

These are both OCaml syntax, just to clarify. The first one is a record type (nominal typing) and the second is an object type (structural typing). They’re covered to great extent in the Real World OCaml book.


#3

This is interesting. That yields a great of number possibilities. I haven’t really used a language that supports both the paradigms. Are structural types generally used in OCaml world or invented just an extension for Bucklescript ecosystem to play nicely with JavaScript and JSON?


#4

Structure types generally used in OCaml and it’s characteristic fit nicely with Javascript.
Bucklescript doesn’t invent new language feature, it just fits existing features to JS.

I would suggest Learn Type-Driven Development by @yawaramin (no affiliation, just a happy reader)


#5

Have you, by any chance, read Domain Modeling Made Functional? I wonder how it compares/combines with Learn Type-Driven Development.

(Not that it would kill me to read both, I guess.)


#6

I haven’t read it personally but looking at its TOC I do see some intersection especially in using types to model the domain, to an extent. Where I expect there will be some differences is that LTDD covers some detailed parametric polymorphism and the specific techniques that are available thanks to the OCaml type system.