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 48D1BBB81 for ; Mon, 10 Oct 2005 14:32:39 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id j9ACWcJt031144 for ; Mon, 10 Oct 2005 14:32:39 +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 OAA21895 for ; Mon, 10 Oct 2005 14:32:38 +0200 (MET DST) Received: from smtp15.wanadoo.fr (smtp15.wanadoo.fr [193.252.23.84]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j9ACWcrV031261 for ; Mon, 10 Oct 2005 14:32:38 +0200 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf1501.wanadoo.fr (SMTP Server) with ESMTP id EA9347000086 for ; Mon, 10 Oct 2005 14:32:37 +0200 (CEST) Received: from wwinf1521 (wwinf1521 [172.22.146.45]) by mwinf1501.wanadoo.fr (SMTP Server) with ESMTP id E7C257000081 for ; Mon, 10 Oct 2005 14:32:37 +0200 (CEST) X-ME-UUID: 20051010123237949.E7C257000081@mwinf1501.wanadoo.fr Message-ID: <3133367.1128947557941.JavaMail.www@wwinf1521> From: yoann padioleau Reply-To: padator@wanadoo.fr To: caml-list@inria.fr Subject: possible to define a type where = is forbidden ? Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [193.54.76.165] X-Wum-Nature: EMAIL-NATURE X-WUM-FROM: |~| X-WUM-TO: |~| X-WUM-REPLYTO: |~| Date: Mon, 10 Oct 2005 14:32:37 +0200 (CEST) X-Miltered: at concorde with ID 434A5F66.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 434A5F66.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; tokens:01 expr:01 expr:01 token:01 compiler:01 occurences:01 functionnal:01 run-time:01 ...:98 ...:98 abstract:01 partial:01 compile:01 functions:01 define:01 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 am making a program analysis tool and in my AST I had previously tokens represented as strings, but now I want also to associate the line numbers of those strings. For instance I had type expr = Plus of expr * expr | ... | Constant of string | Int of int and I want to pass to type expr = Plus of expr * expr | ... | Constant of string extended | Int of int extended where type 'a extended = ('a * int) The problem is that I have in many places some code such as x = y that works well when the AST contain only the string of the token, but now that there is also the line, the x = y is not the good one. I would like a '= modulo I dont care about line' such as for example (Constant "toto",45) =modulo_line= (Constant "toto", 61) be true. There is even some places where I use List.mem that dont work too. Is it possible to define a type such as '=' is forbidden, so that the compiler and the type system will help me to spot all the occurences of = (and List.mem, ...) that I have to change. For the moment my partial solution is to use functions to represented the extended type, because '=' fail at the execution on functionnal value. I want to do: type line_number = int type 'a extended = Abstract of 'a | Concrete of (unit -> ('a * line_number)) where Constant "toto" becomes now (Constant (Concrete (fun () -> "toto", 45)) The problem is that it dectects bad use of = only at run-time. I would prefer a solution that detects the "incrorrect" use of = at compile time. PS: if only caml had typeclasses :)