Skip to content

Commit

Permalink
Merge pull request #344 from samoht/remove-pack
Browse files Browse the repository at this point in the history
Remove pack
  • Loading branch information
dinosaure authored Nov 29, 2020
2 parents e3f87c0 + 3a9476c commit f2cc071
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 35 deletions.
15 changes: 12 additions & 3 deletions bench/cost.ml
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,21 @@ let fake1 = Tuyau.register (module Fake_protocol1)

let fake2 = Tuyau.register (module Fake_protocol2)

module R0 = (val Tuyau.repr fake0)

module R1 = (val Tuyau.repr fake1)

module R2 = (val Tuyau.repr fake2)

let hello_world = "Hello World!\n"

let fn_fully_abstr flow = Benchmark.V (fun () -> Tuyau.send flow hello_world)

let fn_abstr (Tuyau.Flow (flow, (module Flow))) =
Benchmark.V (fun () -> Flow.send flow hello_world)
let fn_abstr = function
| R0.T flow -> Benchmark.V (fun () -> Fake_protocol0.send flow hello_world)
| R1.T flow -> Benchmark.V (fun () -> Fake_protocol1.send flow hello_world)
| R2.T flow -> Benchmark.V (fun () -> Fake_protocol2.send flow hello_world)
| _ -> assert false

type result = {
with_conduit : float;
Expand Down Expand Up @@ -139,7 +148,7 @@ let run json =
Tuyau.connect Unix.stderr fake0 >>= fun flow ->
Tuyau.send flow hello_world >>= fun _ ->
let samples0 = Benchmark.run (fn_fully_abstr flow) in
let samples1 = Benchmark.run (fn_abstr (Tuyau.unpack flow)) in
let samples1 = Benchmark.run (fn_abstr flow) in

match
( Linear_algebra.ols (fun m -> m.(1)) [| (fun m -> m.(0)) |] samples0,
Expand Down
7 changes: 0 additions & 7 deletions src/core/conduit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,6 @@ module Make (IO : IO) (Input : BUFFER) (Output : BUFFER) :
Protocol.connect edn >>| reword_error (msgf "%a" Protocol.pp_error)
>>? fun flow -> return (Ok (Flow.T flow))

type unpack = Flow : 'flow * (module FLOW with type flow = 'flow) -> unpack

let unpack : flow -> unpack =
fun flow ->
let (Value (flow, Flow (_, m))) = Flw.prj flow in
Flow (flow, m)

let impl :
type edn flow.
(edn, flow) protocol ->
Expand Down
26 changes: 1 addition & 25 deletions src/core/conduit_intf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -304,18 +304,6 @@ module type S = sig
match flow with Conduit_tcp.T fd -> Unix.set_nonblock fd | _ -> ()
]} *)

type unpack = Flow : 'flow * (module FLOW with type flow = 'flow) -> unpack

val unpack : flow -> unpack
(** [pack flow] projects the module implementation associated to the given
abstract [flow] such as:
{[
connect edn >>= fun flow ->
let (Flow (flow, (module Flow))) = unpack flow in
Flow.send flow "Hello World!"
]} *)

val impl : ('edn, 'flow) protocol -> ('edn, 'flow) impl
(** [impl protocol] is [protocol]'s implementation. *)

Expand All @@ -325,22 +313,10 @@ module type S = sig
{[
match cast flow Conduit_tcp.t with
| Some (file_descr : Unix.file_descr) ->
Some (Unix.getpeername file_descr)
| Some (fd : Unix.file_descr) -> Some (Unix.getpeername fd)
| None -> None
]} *)

val pack : (_, 'v) protocol -> 'v -> flow
(** [pack protocol concrete_flow] abstracts the given [flow] into the {!flow}
type from a given [protocol]. It permits to use [Conduit] with a concrete
value created by the user.
{[
let socket = Unix.socket Unix.PF_INET Unix.SOCK_STREAM 0 in
let flow = pack Conduit_tcp.t socket in
send flow "Hello World!"
]} *)

(** {2:resolution Domain name resolvers.} *)

type 'edn resolver = Endpoint.t -> 'edn option io
Expand Down

0 comments on commit f2cc071

Please sign in to comment.