4 ms·
You still need virtual dispatch (or type pattern matching) if there is a variable which can contain either a BDRepo or a LoggedRepo(BDRepo).
by _old_dude_ 3y ago
You still need virtual dispatch (or type pattern matching) if there is a variable which can contain either a BDRepo or a LoggedRepo(BDRepo).
- ernst_klim 3y agoNo, 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.