caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Alex Baretta <alex@baretta.com>
To: "caml-list@inria.fr" <caml-list@inria.fr>
Subject: Re: [Caml-list] "Nasty" functions and memory usage
Date: Mon, 19 Mar 2001 16:25:45 +0100	[thread overview]
Message-ID: <3AB624F9.5B6C6680@baretta.com> (raw)
In-Reply-To: <E14exRm-0001kT-00@ithif51>

Hendrik Tews wrote:
> 
>    let f0 = function x,y -> x,y;;
>    let f1 = function x,y -> f1(f0 x, f0 y);;
>    let ...
>    let f5 = function x,y -> f5(f4 x, f4 y);;
> 
> Can you post the correct program? For this I get
> 
>     #   let f1 = function x,y -> f1(f0 x, f0 y);;
> 
>     Characters 26-28:
>     Unbound value f1
> 
> And if I insert let rec's f5 is typechecked in less than a
> second.
> 

That's right. I screwed up. 

let f0 = function x -> x,x;;
let f1 = function x,y -> f0 ( f0 x, f0 y);;
let f2 = function x,y -> f1 ( f1 x, f1 y);;
let f3 = function x,y -> f2 ( f2 x, f2 y);;
let f4 = function x,y -> f3 ( f3 x, f3 y);;
let f5 = function x,y -> f4 ( f4 x, f4 y);;

f0 doubles the size of the type of its argument. f1 doubles twice
the size (*4) of the type of its arguents. f2 multiplies by 4
twice (*16) the size of the type of its argument. f3 multiplies by
16 twice the size of the type of its argument (*256). f4
multiplies its arguments type size by 65536. f5 by 65536**2, which
is 4294967296, or 2**(2**5)). Basically, one sees immediately that
fn has space complexity = k*2**(2**n). A nice double exponential.
Find me a computer capable of f7, now... (3.4*10**38 times the
size of the argument)

Now, my question is, how come the memory usage of the Ocaml (3.00)
front end does not grow with time as it attempts to compute the
type of, say, f6?

Alex
-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr


  parent reply	other threads:[~2001-03-19 15:27 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-17  1:35 Alex Baretta
     [not found] ` <E14exRm-0001kT-00@ithif51>
2001-03-19 15:25   ` Alex Baretta [this message]
2001-03-19 16:01     ` Sebastien Carlier
2001-03-22 14:22 ` Xavier Leroy

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=3AB624F9.5B6C6680@baretta.com \
    --to=alex@baretta.com \
    --cc=caml-list@inria.fr \
    /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;
as well as URLs for NNTP newsgroup(s).