caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* RE: [Caml-list] strange behaviour  with variants and "cannot be g eneralized"
@ 2003-09-09 14:13 Beck01, Wolfgang
  2003-09-09 19:17 ` Didier Remy
  0 siblings, 1 reply; 8+ messages in thread
From: Beck01, Wolfgang @ 2003-09-09 14:13 UTC (permalink / raw)
  To: caml-list

> 
> 
> From: "Beck01, Wolfgang" <BeckW@t-systems.com>
> 
> > v1.ml ----------------------------
> > 
> > open Vtop
> > 
> > type t = {
> >     v1_x : int array;
> > }
> > 
> > let init = `V1 { v1_x = [| 0 |] }
> Sure: [| 0 |] creates a mutable data structure, and as such is
> considered as a side-effecting expression. As a result the type of
> init cannot be generalized.

Funnily, I just found a workaround:
v1.ml ----------------------------
open Vtop

type r_t = {
    r_a : int array;
}

type t = {
    v1_x : r_a;
}
let r_init = { r_a = Array.make 100 0 }
let init = `V1 { v1_x = r_init }
----------------------------------
compiles. However, "let init = `V1 { v1_x = { r_a = Array.make 100 0 }} "
does not. 

> 
> OCaml 3.07 is more clever about that, and the above program would be
> accepted with no problem.
> 
Good to hear. I have introduced variants im my major project after playing
around with toy programs like the one above. But I did not check if
arrays would work. After a week of rearranging my code, I successfully
implemented my first real-world variant (without an array). Then, I
started a second one yesterday and was quite upset when I found that
it did not compile (it took me some time to find that arrays were causing
the trouble). 


Regards,

Wolfgang Beck

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


^ permalink raw reply	[flat|nested] 8+ messages in thread
* RE: [Caml-list] strange behaviour  with variants and "cannot be g eneralized"
@ 2003-09-10  7:10 Beck01, Wolfgang
  2003-09-10  8:12 ` Fernando Alegre
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Beck01, Wolfgang @ 2003-09-10  7:10 UTC (permalink / raw)
  To: caml-list


Didier Remy [mailto:remy@morgon.inria.fr] wrote:

> Here is some explanation of 
> 
>  1) what happened in version 3.06 and 
>  2) how this is related to a relaxed form of value restriction, 
>  3) which is actually orthogonal to the solution implemented in 3.07
> 
> [detailed explanation omitted]

well, I was not aware that compilation of polymorphic variants is an area
of ongoing research. In the OCaml manual, they are not mentioned under
"Language extensions" but as a section in the chapter "An introduction to
Objective Caml". There is a statement

    "In programs, polymorphic variants work like usual ones. You just
    have to prefix their names with a backquote character `."

and this is not true, at least in 3.06. After spending another evening
with weird type errors, I replaced polymorphic variants with ordinary
ones. My project looks uglier now since I had to split up some files,
but at least it compiles and runs.


--
Wolfgang Beck


-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


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

end of thread, other threads:[~2003-09-10 11:34 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-09-09 14:13 [Caml-list] strange behaviour with variants and "cannot be g eneralized" Beck01, Wolfgang
2003-09-09 19:17 ` Didier Remy
2003-09-10  7:10 Beck01, Wolfgang
2003-09-10  8:12 ` Fernando Alegre
2003-09-10  8:18 ` Jacques Garrigue
2003-09-10 10:39   ` skaller
2003-09-10  9:48 ` skaller
2003-09-10 11:34   ` Frederic De Jaeger

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