From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 82C9EBBAF for ; Tue, 10 Jun 2008 13:27:30 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AmUBAJABTkjAXQIniGdsb2JhbACSEAEBAQ8gnQA X-IronPort-AV: E=Sophos;i="4.27,617,1204498800"; d="scan'208";a="13761540" Received: from concorde.inria.fr ([192.93.2.39]) by mail3-smtp-sop.national.inria.fr with ESMTP; 10 Jun 2008 13:27:30 +0200 Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id m5ABRNf3008820 (version=TLSv1/SSLv3 cipher=RC4-SHA bits=128 verify=OK) for ; Tue, 10 Jun 2008 13:27:30 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: An4AAG0CTkjYi40Iomdsb2JhbACSEQEBAQEBAQcFBgkRnQA X-IronPort-AV: E=Sophos;i="4.27,617,1204498800"; d="scan'208";a="13544141" Received: from mail-out8.nyct.net (HELO mail.nyct.net) ([216.139.141.8]) by mail1-smtp-roc.national.inria.fr with ESMTP; 10 Jun 2008 13:27:08 +0200 Received: from [192.168.42.2] (pool-96-246-5-66.nycmny.east.verizon.net [96.246.5.66]) (authenticated bits=0) by mail.nyct.net (8.14.2/8.14.1) with ESMTP id m5ABR5Ya094740 (version=TLSv1/SSLv3 cipher=DHE-DSS-AES256-SHA bits=256 verify=NO); Tue, 10 Jun 2008 07:27:07 -0400 (EDT) (envelope-from bhurt@spnz.org) Date: Tue, 10 Jun 2008 08:01:57 -0400 (EDT) From: Brian Hurt X-X-Sender: bhurt@localhost To: Robert Fischer Cc: caml-list@inria.fr Subject: Re: [Caml-list] Variant type with 'a type? In-Reply-To: <484DE703.50503@smokejumperit.com> Message-ID: References: <484DE703.50503@smokejumperit.com> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Miltered: at concorde with ID 484E651B.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; exn:01 exn:01 struct:01 monads:01 unbound:01 wrote:01 exception:01 exception:01 caml-list:01 variant:02 variant:02 define:02 parameter:02 match:02 module:03 On Mon, 9 Jun 2008, Robert Fischer wrote: > Is it possible to do a variant type along the lines of "type try = Result of 'a | Exception of exn"? > When I try that, I get an error saying "Unbound type parameter 'a". 1) try is a key 2) paramaterize the type. so you can do: type 'a try_t = | Result of 'a | Exception of exn And while you're digging at this spot, let me point out that you might want to define the module like this: module Try = struct let bind m f = match m with | Exception e -> Exception e | Result x -> try f x with | e -> Exception e ;; let ( >>= ) m f = bind m f;; let return x = Result x;; let fail s = Exception (Failure s) end;; Welcome to the wonderful world of monads. Brian