From: Michel Quercia <quercia@cal.enst.fr>
To: Simon Helsen <helsen@informatik.uni-tuebing.de>,
Caml Mailing-list <caml-list@inria.fr>
Subject: Re: recursive datatypes
Date: Wed, 12 Nov 1997 17:16:36 +0100 [thread overview]
Message-ID: <3469D664.905BB6EF@cal.enst.fr> (raw)
In-Reply-To: <Pine.A32.3.96.971111174455.16668X-100000@meijin>
Simon Helsen wrote:
> Why does Caml type-check the following program? It wouldn't in Standard ML
> and I don't see the use for it, as it may lead to infinite programs...
>
> (I don't have a french keyboard)
>
> Pourquoi est le programme ci-desous bon type ? C'est ne pas le
> cas en Standard ML et je ne comprend pas l'usage pour ca parce que le
> programme peut eventuellement cours a l'infini...
>
> type 'a tree = Tree of 'a
>
> let f x = Tree (f x)
>
Hi,
Your code does'nt typecheck with both camllight 0.73 and ocaml 1.05.
With ocaml1.05, the following code does typecheck :
----------------------------------------
Objective Caml version 1.05
# type 'a tree = Tree of 'a;;
type 'a tree = | Tree of 'a
# let f x = Tree (f x);;
Unbound value f
# let rec f x = Tree (f x);;
val f : 'a -> ('b tree as 'b) = <fun>
# f(3);;
Out of memory during evaluation
#
---------------------------------------
I can't explain the "('b tree as 'b)", but why your post is entitled
"recursive datatypes" ?
Did you mean :
type 'a tree = Tree of 'a tree ?
This type declaration is accepted and it is possible to build 'a tree objects
:
--------------------------------------
# type 'a tree = Tree of 'a tree;;
type 'a tree = | Tree of 'a tree
# #print_depth 5;;
# let rec x = Tree(y) and y = Tree(x);;
val x : 'a tree = Tree (Tree (Tree (Tree (Tree (Tree ...)))))
val y : 'a tree = Tree (Tree (Tree (Tree (Tree (Tree ...)))))
-------------------------------------
--
Michel Quercia
Lycee Carnot 16 bd Thiers 21000 Dijon
mailto:quercia@cal.enst.fr
prev parent reply other threads:[~1997-11-13 17:18 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
1997-11-11 16:51 Simon Helsen
1997-11-12 15:05 ` Xavier Leroy
1997-11-12 16:16 ` Michel Quercia [this message]
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=3469D664.905BB6EF@cal.enst.fr \
--to=quercia@cal.enst.fr \
--cc=caml-list@inria.fr \
--cc=helsen@informatik.uni-tuebing.de \
/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