caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* possible to define a type where = is forbidden ?
@ 2005-10-10 12:32 yoann padioleau
  2005-10-10 13:18 ` [Caml-list] " Christian Lindig
  0 siblings, 1 reply; 4+ messages in thread
From: yoann padioleau @ 2005-10-10 12:32 UTC (permalink / raw)
  To: caml-list


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 :)




^ permalink raw reply	[flat|nested] 4+ messages in thread
* Re: [Caml-list] possible to define a type where = is forbidden ?
@ 2005-10-10 13:42 yoann padioleau
  2005-10-10 15:04 ` Thomas Fischbacher
  0 siblings, 1 reply; 4+ messages in thread
From: yoann padioleau @ 2005-10-10 13:42 UTC (permalink / raw)
  To: Christian Lindig; +Cc: Caml List


> On Oct 10, 2005, at 2:32 PM, yoann padioleau wrote:
> 
> > 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.
> 
> I like to suggest a different technique that does not require to change  
> the representation of all branches in an AST. You can find it in an  
> earlier posting here:
> 
> http://caml.inria.fr/pub/ml-archives/caml-list/2003/09/ 
> f81c8063ed4878e06f1ddd8010256050.en.html

Interesting technique :)  but I think that it would not solve my problem. 

To be more precise my program analysis tool  try to compute "diff" between differents AST.
So we love to use pattern-patching and to (ab)use the polymorphic  =  to compare stuff.

I don't see how your ExprAt technique will make this easier (not to mention that it also makes 
the pattern matching ugly because I would have to wrap every  expression  with his ExprAt  because I want
that the resultting  Ast_diff  contain also line number.





^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-10-10 15:04 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-10-10 12:32 possible to define a type where = is forbidden ? yoann padioleau
2005-10-10 13:18 ` [Caml-list] " Christian Lindig
2005-10-10 13:42 yoann padioleau
2005-10-10 15:04 ` Thomas Fischbacher

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).