From: yoann padioleau <padator@wanadoo.fr>
To: caml-list@inria.fr
Subject: possible to define a type where = is forbidden ?
Date: Mon, 10 Oct 2005 14:32:37 +0200 (CEST) [thread overview]
Message-ID: <3133367.1128947557941.JavaMail.www@wwinf1521> (raw)
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 :)
next reply other threads:[~2005-10-10 12:32 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2005-10-10 12:32 yoann padioleau [this message]
2005-10-10 13:18 ` [Caml-list] " Christian Lindig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3133367.1128947557941.JavaMail.www@wwinf1521 \
--to=padator@wanadoo.fr \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox