From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p4KC3aYa003762 for ; Fri, 20 May 2011 14:03:37 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlAFAB5X1k1QW+UMgWdsb2JhbACYHo19FAEBFiYlpSSfKoYZBI1igi+OdQ X-IronPort-AV: E=Sophos;i="4.65,242,1304287200"; d="scan'208";a="95075139" Received: from lo.gmane.org ([80.91.229.12]) by mail2-smtp-roc.national.inria.fr with ESMTP; 20 May 2011 14:03:31 +0200 Received: from list by lo.gmane.org with local (Exim 4.69) (envelope-from ) id 1QNOQT-00036L-9P for caml-list@inria.fr; Fri, 20 May 2011 14:03:29 +0200 Received: from ks368928.kimsufi.com ([94.23.39.26]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 20 May 2011 14:03:29 +0200 Received: from sylvain by ks368928.kimsufi.com with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 20 May 2011 14:03:29 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Sylvain Le Gall Date: Fri, 20 May 2011 12:03:17 +0000 (UTC) Message-ID: X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: ks368928.kimsufi.com User-Agent: slrn/pre1.0.0-18 (Linux) X-Validation-by: sylvain@le-gall.net Subject: [Caml-list] Types for solved and unsolved conditional values Hello all, I would like to express a conditional value that can be either solved or unsolved and be able to quickly match the result, in the case of a solved value. The value returned should be 'a. Some code: type ('a, 'b) conditional type 'a unsolved = ('a, (expr, 'a) list) conditional type 'a solved = ('a, [`Always 'a | `NotSolved]) conditional (* Unsolved conditional *) let myval = [EFlag "foo", "foo"; EBool true, "nofoo"] (* Solved conditional *) let myval' = `Always "foo" A basic solution would be to make types independent, this way: type ('a, 'b) conditional = 'a, (expr * 'b) list type 'a unsolved = ('a, unit) conditional type 'a solved = ('a, [`Always of int | `NotSolved]) conditional let myval = (), [EFlag "foo", "foo"; EBool true, "nofoo"] let myval' = `Always 0, [EFlag "foo", "foo"; EBool true, "nofoo"] But I don't feel it is the right solution. Is there any way to do it better ? Cheers, Sylvain Le Gall -- My company: http://www.ocamlcore.com Linkedin: http://fr.linkedin.com/in/sylvainlegall Start an OCaml project here: http://forge.ocamlcore.org OCaml blogs: http://planet.ocamlcore.org