* Why isn't -rectypes command line option the default
@ 2007-03-21 0:34 Erik de Castro Lopo
2007-03-21 1:48 ` Zheng Li
0 siblings, 1 reply; 8+ messages in thread
From: Erik de Castro Lopo @ 2007-03-21 0:34 UTC (permalink / raw)
To: caml-list
Hi all,
If I try to define a recursive type like this:
type 'a t = 'a * 'a t Lazy.t
the compiler won't accept it unless I add -rectypes to the compile
command.
I know I can avoid this by using a tag:
type 'a t = Node of 'a * 'a t Lazy.t
but I was wondering if there was a reason why -rectypes wasn't the
default.
Cheers,
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
"The very definition of hell is having to maintain someone
else's Perl code." -- Anonymous
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Why isn't -rectypes command line option the default
2007-03-21 0:34 Why isn't -rectypes command line option the default Erik de Castro Lopo
@ 2007-03-21 1:48 ` Zheng Li
2007-03-21 2:13 ` [Caml-list] " Erik de Castro Lopo
0 siblings, 1 reply; 8+ messages in thread
From: Zheng Li @ 2007-03-21 1:48 UTC (permalink / raw)
To: caml-list
Erik de Castro Lopo <mle+ocaml@mega-nerd.com> writes:
> but I was wondering if there was a reason why -rectypes wasn't the
> default.
It's consciously disabled to avoid mysterious report of errors. Many careless
coding errors can be typed with recursive types, for example
# fun x-> x::x;;
- : ('a list as 'a) -> 'a list = <fun>
in this case, the programmer is probably thinking of connecting @ two
list. With recursive types, instead of a immediately type error report in
place, the function is typed without any problem, and finally some accident may
be happened far away from here, where the original function is likely to be under
several layers of composition and hard to recognized.
So the main consideration is safety, though it's really fun to play with
recursive types sometimes.
--
Zheng Li
http://www.pps.jussieu.fr/~li
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Re: Why isn't -rectypes command line option the default
2007-03-21 1:48 ` Zheng Li
@ 2007-03-21 2:13 ` Erik de Castro Lopo
2007-03-21 5:37 ` james woodyatt
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: Erik de Castro Lopo @ 2007-03-21 2:13 UTC (permalink / raw)
To: caml-list
Zheng Li wrote:
> So the main consideration is safety, though it's really fun to play with
> recursive types sometimes.
Ok, I can see why they aren't on by default, but using -rectypes on
the whole file exposes to the whole file to these errors.
Wouldn't it be nicer to be able to specify the rectypes behaviour
per type? Maybe something like this would work:
rec type 'a t = 'a * 'a t Lazy.t
Cheers,
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
"Mutable state is actually another form of manual memory management: every
time you over-write a value you are making a decision that the old value is
now garbage, regardless of what other part of the program might have been
using it." -- Paul Johnson
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Re: Why isn't -rectypes command line option the default
2007-03-21 2:13 ` [Caml-list] " Erik de Castro Lopo
@ 2007-03-21 5:37 ` james woodyatt
2007-03-21 7:08 ` Erik de Castro Lopo
2007-03-21 9:01 ` Ville-Pertti Keinonen
2007-03-21 12:47 ` Gerd Stolpmann
2 siblings, 1 reply; 8+ messages in thread
From: james woodyatt @ 2007-03-21 5:37 UTC (permalink / raw)
To: The Caml Trade
On Mar 20, 2007, at 19:13, Erik de Castro Lopo wrote:
>
> Wouldn't it be nicer to be able to specify the rectypes behaviour
> per type? Maybe something like this would work:
>
> rec type 'a t = 'a * 'a t Lazy.t
You know... I have found myself on several occasions wishing for
something like that. A nitpick: I think I'd be happier with "type
rec" as opposed to "rec type" since that seems symmetrical with the
"let rec" phrasing. Yes, I would expect "type rec a = ... and b
= ... and c = ..." to allow all three types to be recursive.
—
j h woodyatt <jhw@conjury.org>
http://jhw.vox.com/
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Re: Why isn't -rectypes command line option the default
2007-03-21 5:37 ` james woodyatt
@ 2007-03-21 7:08 ` Erik de Castro Lopo
0 siblings, 0 replies; 8+ messages in thread
From: Erik de Castro Lopo @ 2007-03-21 7:08 UTC (permalink / raw)
To: caml-list
james woodyatt wrote:
> You know... I have found myself on several occasions wishing for
> something like that. A nitpick: I think I'd be happier with "type
> rec" as opposed to "rec type" since that seems symmetrical with the
> "let rec" phrasing.
Sure, either way would be really great.
Erik
--
+-----------------------------------------------------------+
Erik de Castro Lopo
+-----------------------------------------------------------+
"The question of whether a computer can think is no more interesting
than the question of whether a submarine can swim." -- edsger dijkstra
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Re: Why isn't -rectypes command line option the default
2007-03-21 2:13 ` [Caml-list] " Erik de Castro Lopo
2007-03-21 5:37 ` james woodyatt
@ 2007-03-21 9:01 ` Ville-Pertti Keinonen
2007-03-21 12:47 ` Gerd Stolpmann
2 siblings, 0 replies; 8+ messages in thread
From: Ville-Pertti Keinonen @ 2007-03-21 9:01 UTC (permalink / raw)
To: Erik de Castro Lopo; +Cc: caml-list
On Mar 21, 2007, at 4:13 AM, Erik de Castro Lopo wrote:
> Wouldn't it be nicer to be able to specify the rectypes behaviour
> per type? Maybe something like this would work:
>
> rec type 'a t = 'a * 'a t Lazy.t
It would probably be possible to allow that by default with no extra
keyword, since errors are unlikely when writing a type explicitly.
But the ability to write recursive type aliases would not make
actually creating recursively typed values all that convenient, you'd
have to give the type explicitly (I'd rather just use a variant and a
constructor).
Note that in the example using -rectypes posted by Zheng Li, the type
'a t is never actually used for anything - presumably it's intended
as an illustration to the reader, and could just as well be a comment
- the type inferred for fib is compatible, but not named int t.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Re: Why isn't -rectypes command line option the default
2007-03-21 2:13 ` [Caml-list] " Erik de Castro Lopo
2007-03-21 5:37 ` james woodyatt
2007-03-21 9:01 ` Ville-Pertti Keinonen
@ 2007-03-21 12:47 ` Gerd Stolpmann
2 siblings, 0 replies; 8+ messages in thread
From: Gerd Stolpmann @ 2007-03-21 12:47 UTC (permalink / raw)
To: Erik de Castro Lopo; +Cc: caml-list
Am Mittwoch, den 21.03.2007, 13:13 +1100 schrieb Erik de Castro Lopo:
> Zheng Li wrote:
>
> > So the main consideration is safety, though it's really fun to play with
> > recursive types sometimes.
>
> Ok, I can see why they aren't on by default, but using -rectypes on
> the whole file exposes to the whole file to these errors.
>
> Wouldn't it be nicer to be able to specify the rectypes behaviour
> per type? Maybe something like this would work:
>
> rec type 'a t = 'a * 'a t Lazy.t
You can do that:
type 'a t = T of 'a * 'a t Lazy.t
Recursive types are accepted without -rectypes when the recursion
crosses a variant type. Note that the runtime costs are usually
negligible.
Gerd
--
------------------------------------------------------------
Gerd Stolpmann * Viktoriastr. 45 * 64293 Darmstadt * Germany
gerd@gerd-stolpmann.de http://www.gerd-stolpmann.de
Phone: +49-6151-153855 Fax: +49-6151-997714
------------------------------------------------------------
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Why isn't -rectypes command line option the default
@ 2007-03-21 1:24 Jeffrey Loren Shaw
0 siblings, 0 replies; 8+ messages in thread
From: Jeffrey Loren Shaw @ 2007-03-21 1:24 UTC (permalink / raw)
To: caml-list
For one reason why, see
http://caml.inria.fr/pub/docs/manual-ocaml/libref/Lazy.html
I remember reading other reasons, but I can't seem to find them right now.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2007-03-21 12:47 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-21 0:34 Why isn't -rectypes command line option the default Erik de Castro Lopo
2007-03-21 1:48 ` Zheng Li
2007-03-21 2:13 ` [Caml-list] " Erik de Castro Lopo
2007-03-21 5:37 ` james woodyatt
2007-03-21 7:08 ` Erik de Castro Lopo
2007-03-21 9:01 ` Ville-Pertti Keinonen
2007-03-21 12:47 ` Gerd Stolpmann
2007-03-21 1:24 Jeffrey Loren Shaw
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox