From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 9FB417EE94 for ; Fri, 28 Dec 2012 10:37:36 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of grazingcows@yahoo.com) identity=pra; client-ip=98.136.217.18; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="grazingcows@yahoo.com"; x-sender="grazingcows@yahoo.com"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of grazingcows@yahoo.com) identity=mailfrom; client-ip=98.136.217.18; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="grazingcows@yahoo.com"; x-sender="grazingcows@yahoo.com"; x-conformance=sidf_compatible Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@nm35.bullet.mail.gq1.yahoo.com) identity=helo; client-ip=98.136.217.18; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="grazingcows@yahoo.com"; x-sender="postmaster@nm35.bullet.mail.gq1.yahoo.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AugNAERn3VBiiNkSamdsb2JhbAA3BAmCSY0Kmz+SVBYODQkMBhQpghkFAQEFCxwEFQECFRYMAQ4GBREEAQEBDSEvAQ4BBgoIBhMSCYdlAQECDwQIpS8JgnKED0gBIwMBIwOIdAEGCgEBjEsFDYQxA4hijTGBFYRPLlCIFWuDdA X-IronPort-AV: E=Sophos;i="4.84,368,1355094000"; d="scan'208,217";a="166943654" Received: from nm35.bullet.mail.gq1.yahoo.com ([98.136.217.18]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Dec 2012 10:37:34 +0100 Received: from [98.137.12.191] by nm35.bullet.mail.gq1.yahoo.com with NNFMP; 28 Dec 2012 09:37:31 -0000 Received: from [98.137.12.247] by tm12.bullet.mail.gq1.yahoo.com with NNFMP; 28 Dec 2012 09:37:31 -0000 Received: from [127.0.0.1] by omp1055.mail.gq1.yahoo.com with NNFMP; 28 Dec 2012 09:37:31 -0000 X-Yahoo-Newman-Property: ymail-3 X-Yahoo-Newman-Id: 548392.17401.bm@omp1055.mail.gq1.yahoo.com Received: (qmail 86193 invoked by uid 60001); 28 Dec 2012 09:37:31 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1356687451; bh=X9305ekopiTiRJ9ttN3vgJOEOeV/G3pVeEdaUQqdW8g=; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=j0OI2UHM97ZkOeS1ws+nKpx7gS+3bYqSRqG51Uadx4niZAG35sNtAEdcFo6/7+m6KVYr57gyDt6GGe8ERpuAIU9pFD3C1OfOiBuaN6Kdn7VcJxJGpjH7SC9Oml/Kz4262CjV1Z6jfr3OwLPMfc+LA3PwQF30eSXUPPqa7KUEpe4= DomainKey-Signature:a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=X-YMail-OSG:Received:X-Rocket-MIMEInfo:X-Mailer:References:Message-ID:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=pFWXwj/6Fx03+RQx/WGfDpa6ATIJJwNfcQrWyunU+WbDhR8dINKUTHZx7LfamIklEf4+g+o2fjEX6qQSb+MNrL7arkqyiZZ4GWnUb5nnM1ZyUelXGlitqrHQFzSmx/LIMHS1Cw2odoGFUu2odfrljH9suOfFRokZpdFtkcpkris=; X-YMail-OSG: QCtC68MVM1nzCXvuAziWjih4RHmsOlvwnsXT4HhlYZEEVV6 wz4NoJX.dD14Ni4G5Ui3H65eBjXbeWl9FZUCJbdbg9V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hIHRydWUgJ2MBMAEBAQE- X-Mailer: YahooMailWebService/0.8.129.483 References: <003801cddcfa$f66325c0$e3297140$@jaeger@ssi.gouv.fr> <50D59147.3000201@ssi.gouv.fr> Message-ID: <1356687451.79354.YahooMailNeo@web163402.mail.gq1.yahoo.com> Date: Fri, 28 Dec 2012 01:37:31 -0800 (PST) From: Arkady Andrukonis Reply-To: Arkady Andrukonis To: "caml-list@inria.fr" In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="303371348-562022172-1356687451=:79354" Subject: Re: [Caml-list] Function returning recursive lists --303371348-562022172-1356687451=:79354 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable Hi,=A0 You cannot have a circular recursive definition let rec ls =3D [1; 2; 3; ls; ] ;; but you can have a "circular" list: let rec ls =3D [1; 2; 3;] :: ls ;; it creates 40 items, the first 38 are [1; 2; 3;] and the 39 is=A0 [1; 2; ...]; and the last [...].=A0 We cannot say it is a true 'circular' list, because we don't return from the last element to the=A0 first element. At any rate this will result=20 in an expression that is nested too deep and=20 we won't be able to use it. The ellipsis [...] has the force of 'any' but it returns the same element as before, a list of lists. An example of a not very useful circular list in the literature=20 shows a continuous loop let rec process =3D 1 :: 2 :: 3 :: 4 :: 5 :: process;; while true do =A0 let process :: process =3D process in =A0 printf "Handling =A0process %d\n" process; =A0 Unix.sleep 2; done ;; ________________________________ From: Peter Frey To: Eric Jaeger (ANSSI) =20 Cc: caml-list@inria.fr=20 Sent: Thursday, December 27, 2012 8:41 PM Subject: Re: [Caml-list] Function returning recursive lists =20 On Sat, 2012-12-22 at 11:53 +0100, Eric Jaeger (ANSSI) wrote:=20 > On 21/12/2012 20:55, Peter Frey wrote: > > It sometimes helps to read read the various libraries. > > For example, this thing is a variation of Batteries.BatList.Append: > > > > module Cycle =3D struct > >=A0 =A0 type 'a mut_list =3D { hd: 'a; mutable tl: 'a list } > >=A0 =A0 external inj : 'a mut_list -> 'a list =3D "%identity" > >=A0 =A0 external jni : 'a list -> 'a mut_list =3D "%identity" > As far as I know, the use of "%identity" is a trick which is similar to= =20 > Obj, telling the compiler to do nothing. You would not be allowed to do= =20 > that with standard, typed OCaml identity. In this sense, it is not the=20 > sort of solution I'm looking for. >=20 >=A0 =A0 Regards, Eric For what it's=A0 worth: Obj.ml, contains the line: ... external magic : 'a -> 'b =3D "%identity" ... That type allows anything, including 'unifying' any two types. (The compiler does not do nothing: it assigns the argument of type 'a to be the result which is of type 'b and is perfectly willing to produce code that instantly causes a segmentation fault) inj and its inverse jni seem to have a type at least a bit more friendly since they control the usage of the individual fields. As long as you trust Ocaml lists to always have the layout above, this seems a lot saver to me than type 'a -> 'b. You wanted, in effect, something like: # let rec l =3D [1;2;3;l];; Error: This expression has type int list =A0 =A0 =A0 but an expression was expected of type int The type 'a list is built into the system; it is not recursive and if there was a way to force it to be so (without hacks), the type system would not be sound. You know the following, of course: # type 'a aRec =3D {mutable hd: 'a; mutable tl:'a aRec};; type 'a aRec =3D { mutable hd : 'a; mutable tl : 'a aRec; } # let rec a =3D {hd=3D1; tl=3Da};;=A0 =A0 =A0 =A0 =A0=20 val a : int aRec =3D =A0 {hd =3D 1; =A0 tl =3D =A0 =A0 {hd =3D 1; =A0 =A0 tl =3D =A0 =A0 =A0 {hd =3D 1; =A0 =A0 =A0 tl =3D =A0 =A0 =A0 =A0 {hd =3D 1; =A0 =A0 =A0 =A0 tl =3D The problem with docycle is not its coding style but that it produces in fact a cyclic list, which is not very useful: Almost all functions, such as List.rev are undefined.=20 Peter --=20 Caml-list mailing list.=A0 Subscription management and archives: https://sympa.inria.fr/sympa/arc/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs= --303371348-562022172-1356687451=:79354 Content-Type: text/html; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable
Hi, 

You cannot have a circular recursi= ve definition
let rec ls =3D [1; 2; 3; ls; ] ;;
but you can have a "circular" list:
let rec ls =3D [1; 2; 3;] :: = ls ;;
it creates 40 items,
the first 38 are = [1; 2; 3;] and the 39 is 
[1; 2; ...]; and the last [...].&n= bsp;
We cannot say it is a true 'circular' list, because
we don't return from the last element to the 
first elemen= t. At any rate this will result
in an expression that is nested = too deep and
we won't be able to use it. The ellipsis [...] has<= /div>
the force of 'any' but it returns the same element
as b= efore, a list of lists. An example of a not
very useful circular = list in the literature
shows a continuous loop
let rec= process =3D 1 :: 2 :: 3 :: 4 :: 5 :: process;;
while true do
  let process :: process =3D process in
  printf "Handling  process %d\n" process;
  Unix.sleep = 2;
done ;;

From: Peter Frey <pjfrey@sympatico.ca>
= To: Eric Jaeger (ANSSI) &= lt;eric.jaeger@ssi.gouv.fr>
Cc= : caml-list@inria.fr
= Sent: Thursday, December 27, 2012 8:41 PM
Subject: Re: [Caml-list] Function returning = recursive lists

On Sat, 2012-12-22 at 11:53 +0100, Eric Jaeger (ANSSI) wrote:
> On 2= 1/12/2012 20:55, Peter Frey wrote:
> > It sometimes helps to read = read the various libraries.
> > For example, this thing is a varia= tion of Batteries.BatList.Append:
> >
> > module Cycle = =3D struct
> >    type 'a mut_list =3D { hd: 'a; mutable= tl: 'a list }
> >    external inj : 'a mut_list -> '= a list =3D "%identity"
> >    external jni : 'a list -&g= t; 'a mut_list =3D "%identity"
> As far as I know, the use of "%ident= ity" is a trick which is similar to
> Obj, telling the compiler to d= o nothing. You would not be allowed to do
> that with standard, type= d OCaml identity. In this sense, it is not the
> sort of solution I'= m looking for.
>
>    Regards, Eric

For what = it's  worth: Obj.ml, contains the line:
...
external magic : 'a -> 'b =3D "%identity"<= br>...
That type allows anything, including 'unifying' any two types.(The compiler does not do nothing: it assigns the argument of type 'a tobe the result which is of type 'b and is perfectly willing to produce
= code that instantly causes a segmentation fault)

inj and its inverse= jni seem to have a type at least a bit more friendly
since they control= the usage of the individual fields.
As long as you trust Ocaml lists to= always have the layout above, this
seems a lot saver to me than type 'a= -> 'b.

You wanted, in effect, something like:
# let rec l =3D= [1;2;3;l];;
Error: This expression has type int list
    &= nbsp; but an expression was expected of type int

The type 'a list i= s built into the system; it is not recursive and if
there was a way to f= orce it to be so (without hacks), the type system
would not be sound.

You know the following, of course:

# type 'a aRec =3D= {mutable hd: 'a; mutable tl:'a aRec};;
type 'a aRec =3D { mutable hd : = 'a; mutable tl : 'a aRec; }

# let rec a =3D {hd=3D1; tl=3Da};; =        
val a : int aRec =3D
  {hd =3D 1;=
  tl =3D
    {hd =3D 1;
    tl =3D
=       {hd =3D 1;
      tl =3D
  &= nbsp;     {hd =3D 1;
        tl =3D
The problem with docycle is not its coding style but that it produces in<= br>fact a cyclic list, which is not very useful: Almost all functions, such=
as List.rev are undefined.


Peter





-- =
Caml-list mailing list.  Subscription management and archives:
= ht= tps://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.= inria.fr/bin/caml-bugs


= --303371348-562022172-1356687451=:79354--