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.
I’m a professional software writer specialized in Web technologies and engaged in indie application development. I consider myself to be a man of faith. I pursue honesty, integrity, and compassion.
You could also go:
Sure, calling
getUser(UserId(user.id))
is as verbose asgetUser(~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-wideuserId
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!