Le Monday 04 Apr 2011 à 02:37:59 (+0100), Pedro Borges a écrit :
> On Mon, Apr 4, 2011 at 2:09 AM, Guillaume Yziquel
> <guillaume.yziq...@citycable.ch> wrote:
> > It's nice to have phantom types to have usage of sockets type checked.
> > But if it prevents them from being bundled in an array for zmq_poll(),
> > there has to be a workaround.
> >
> > One would be to have them carrying their types around at runtime. Not so
> > lean. Another would be to have a declaration like
> >
> >        type 'a typed_socket = private untyped_socket
> >
> > allowing you to subtype a typed socket into an untyped_socket, but not
> > the other way round as that would not be safe.
> 
> Currently ocaml-zmq declares the socket type parameter covariant and
> every type parameter private of "generic" so you can cast any socket
> like this:
> 
>     let a : pub Socket.t = ...
>     let b = ( a :> generic Socket.t)

Not bad at all. It's not as rigorous as maths, but has the huge
advantage of not polluting the namespace for types. Great.

-- 
     Guillaume Yziquel
_______________________________________________
zeromq-dev mailing list
zeromq-dev@lists.zeromq.org
http://lists.zeromq.org/mailman/listinfo/zeromq-dev

Reply via email to