From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 5BDA07EEBF for ; Fri, 24 Jul 2015 13:01:16 +0200 (CEST) Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of markus.weissmann@in.tum.de) identity=pra; client-ip=131.159.0.8; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="markus.weissmann@in.tum.de"; x-sender="markus.weissmann@in.tum.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of markus.weissmann@in.tum.de) identity=mailfrom; client-ip=131.159.0.8; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="markus.weissmann@in.tum.de"; x-sender="markus.weissmann@in.tum.de"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-out1.informatik.tu-muenchen.de) identity=helo; client-ip=131.159.0.8; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="markus.weissmann@in.tum.de"; x-sender="postmaster@mail-out1.informatik.tu-muenchen.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CUBACRGrJVnAgAn4Nbg2lpgyO6V4dKTAEBAQEBARIBAQEBAQgLCQkhLkEChAoECwEFVSECJgJfG4gmpFCPX5YzgSKOZ2mCUoFDBZRjjkeGRJBVgXwBNB+BVTwxgksBAQE X-IPAS-Result: A0CUBACRGrJVnAgAn4Nbg2lpgyO6V4dKTAEBAQEBARIBAQEBAQgLCQkhLkEChAoECwEFVSECJgJfG4gmpFCPX5YzgSKOZ2mCUoFDBZRjjkeGRJBVgXwBNB+BVTwxgksBAQE X-IronPort-AV: E=Sophos;i="5.15,538,1432591200"; d="scan'208";a="141078454" Received: from mail-out1.informatik.tu-muenchen.de ([131.159.0.8]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 24 Jul 2015 13:01:15 +0200 Received: from webmail.in.tum.de (localhost [127.0.0.1]) by vmwebmail1.informatik.tu-muenchen.de (Postfix) with ESMTP id 2344D240788 for ; Fri, 24 Jul 2015 13:01:13 +0200 (CEST) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Date: Fri, 24 Jul 2015 13:01:13 +0200 From: =?UTF-8?Q?Markus_Wei=C3=9Fmann?= To: Message-ID: X-Sender: markus.weissmann@in.tum.de User-Agent: Roundcube Webmail/0.8.1 Subject: [Caml-list] Clever typing for client-server communication? Hello OCaml list, I'm trying to do something clever regarding the interface for a communication library: There is a server and a client which can only send "client" (client to server) and "server" (server to client) messages. The current idea is to use a phantom type to annotate the socket as either being "client to server" or "server to client"; type client type server type ('a, 'b) socket type 'a message I've got a bunch of functions that only work on either "client messages", "server messages" or some on both. Something like: val p1 : 'a message -> int val p2 : server message -> float val p3 : client message -> char You can only send "client messages" on the "client socket" and "server messages" on the "server socket". val send : ('a, _) socket -> 'a message -> unit You can get these messages only on the respective other side. val recv : (_, 'b) socket -> 'b message but is there some clever way to only have the socket annotated with one type while keeping only one send and one recv function? Something in the spirit of this: type 'a socket val send : 'a socket -> 'a message -> unit val recv : [server socket -> client message | client socket -> server message] there is no "(client, client) socket" or "(server, server) socket"; regards -Markus PS: Under the hood its basically type 'a message = bytes type ('a, 'b) socket = mysocket But the underlying system allows me to add filters that guarantee me the aforementioned properties of send/receive. regards Markus -- Markus Weißmann, M.Sc. Technische Universität München Institut für Informatik Boltzmannstr. 3 D-85748 Garching Germany http://wwwknoll.in.tum.de/