English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
beginner question: DAGs w/ recursive types an encapsulation of a Map
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2007-05-06 (07:54)
From: Alain Frisch <Alain.Frisch@i...>
Subject: Re: [Caml-list] beginner question: DAGs w/ recursive types an encapsulation of a Map
Jon Harrop wrote:
> # type tree' =  int  * (char * tree') list ;;
> type tree' = int * (char * tree') list
> This is not "unsafe" in the usual sense of the word but it means that the 
> compiler will be less friendly on all of the rest of your code. 

The declaration is not "unsafe" by itself, but the -rectypes option is,
in the sense that it will make the compiler accept programs that will
produce infinite loops in the run-time system:


<< Note: if the program is compiled with the -rectypes option,
ill-founded recursive definitions of the form let rec x = lazy x  or let
rec x = lazy(lazy(...(lazy x))) are accepted by the type-checker and
lead, when forced, to ill-formed values that trigger infinite loops in
the garbage collector and other parts of the run-time system. Without
the -rectypes option, such ill-founded recursive definitions are
rejected by the type-checker. >>

(One might argue that the type checker does not reject non-terminating
programs anyway.)

-- Alain