When should I use single case constructors or type aliases?

You can also avoid this logic issue by using modules, which is what we typically do:

module Dog = struct
  type t = { name : string }
end

module Cat = struct
  type t = { name : string }
end

Now we will have to create and pattern-match the record types using their explicit module names eg { Dog.name = "Brian" }.

1 Like