re: Get compiler help, even with “stringly” typed parameters in ReasonML VIEW POST


You could also go:

type userId =
  | UserId(string);
let getUser = (userId: userId) /* ... */

Sure, calling getUser(UserId(user.id)) is as verbose as getUser(~userId: user.id)—provided you want to leave those naked strings in all the other places. But maybe it makes more sense to have app-wide userId type anyway and not let strings wander any further than JSON encoding/decoding and suchlike.

You could probably also use phantom types, but I’m not sure if those are easy to use across modules, or whether putting all the user-related business logic in the User module is actually better than just an app-wide type. I’m still new to functional languages.


Definitely other good approaches. Thanks, Sergey!

code of conduct - report abuse