6 ms·
No, you don't. LocalRepo.t != Repo.t, and all the functions are purely static. LocalRepo.get_user won't work with other Repo.t, and other Repo.get_user won't wo
by ernst_klim 3y ago
No, you don't. LocalRepo.t != Repo.t, and all the functions are purely static. LocalRepo.get_user won't work with other Repo.t, and other Repo.get_user won't work with LocalRepo.t. What you would need is to parametrize your further computation with a Repo module, as in
module HttpHandler (R : Repo) : sig
val handle_user : R.t -> HttpWriter.t -> username:string -> unit
end = struct
let handle_user repo writer ~username =
match R.get_user repo username with
| None -> Writer.write_status writer 404
| Some user -> Writer.write_body writer (User.to_string user)
end
and then to construct a handler module with a proper repo.