From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 25E0CBB84 for ; Thu, 29 Jun 2006 23:27:52 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k5TLRqrt011237 for ; Thu, 29 Jun 2006 23:27:52 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id XAA14523 for ; Thu, 29 Jun 2006 23:27:51 +0200 (MET DST) Received: from furbychan.cocan.org (furbychan.cocan.org [80.68.91.176]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k5TLRmp8015742 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Thu, 29 Jun 2006 23:27:51 +0200 Received: from rich by furbychan.cocan.org with local (Exim 3.35 #1 (Debian)) id 1Fw42f-0003aQ-00 for ; Thu, 29 Jun 2006 22:27:17 +0100 Date: Thu, 29 Jun 2006 22:27:17 +0100 To: caml-list@inria.fr Subject: Another question on variant types and matching (was: Re: [Caml-list] Question on Variant Types) Message-ID: <20060629212717.GA32073@furbychan.cocan.org> References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.9i From: Richard Jones X-Miltered: at concorde with ID 44A445D8.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44A445D4.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; foreground:01 foreground:01 endline:01 endline:01 notepad:01 caml-list:01 variant:02 variant:02 string:02 string:02 types:02 types:02 seems:03 blue:96 blue:96 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 I have another question on variant types which seems to be related to this, but perhaps the opposite way round. How can I get the code below to work? (It's simplified greatly from a real problem I'm having). Rich. ---------------------------------------------------------------------- type colour = [ `Red | `Green | `Blue ] type colour' = [ colour | `Default ] type instructions = Set_foreground of colour' | Set_background of colour' let default_fg : colour = `Red let default_bg : colour = `Green let process_instructions = List.fold_left ( fun (fg, bg) -> function | Set_foreground `Default -> let new_fg = default_fg in (new_fg, bg) | Set_foreground new_fg -> (new_fg, bg) | Set_background `Default -> let new_bg = default_bg in (fg, new_bg) | Set_background new_bg -> (fg, new_bg) ) let string_of_colour = function | `Red -> "red" | `Green -> "green" | `Blue -> "blue" let () = let instrs = [ Set_foreground `Blue; Set_background `Red; Set_foreground `Default ] in let fg, bg = `Green, `Blue in let fg, bg = process_instructions (fg, bg) instrs in print_endline ("fg = " ^ string_of_colour fg); print_endline ("bg = " ^ string_of_colour bg) ---------------------------------------------------------------------- -- Richard Jones, CTO Merjis Ltd. Merjis - web marketing and technology - http://merjis.com Team Notepad - intranets and extranets for business - http://team-notepad.com