Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] pretty printers and format and matrices
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Frank Atanassow <franka@c...>
Subject: Re: [Caml-list] pretty printers and format and matrices
Pierre Weis wrote (on 14-06-01 21:37 +0200):
> On a regular machine this allows to simultaneously open no more than
> 4611686018427387903 boxes, which could be large enough to pretty print
> a huge source chunk of your programming language source programs. On
> the other hand, on my Ipaq handheld this limit is much smaller than
> that, namely 1073741823 which may be really short for you.
> 
> If you need more than max_int simultaneously open boxes, you should
> rewrite the Format module using the bignumbers facility of
> Caml. However, I should admit that you will still be facing another
> stupid limit (no more than 2^30 words in a big integer, which means
> approximately 9 * 2 ^ 30 decimal digits on a little machine, once more
> far far away from infinity). If you really need infinity, I am not aware
> of any practical solution in Objective Caml.
> 
> Sorry for this unsatisfactory answer, due to stupid limitations in the
> language.

Obviously the solution is to rewrite Format so that the box numbers are
encoded as Church numerals. Then you can easily represent infinity:

  let zero = fun z s -> z;;
  let succ n = fun z s -> let s' = s () in s' (n z s);;
  (* unfortunately, eta-expansion needed because of value restriction *)
  let one = fun z s -> succ zero z s;;
  let two = fun z s -> succ one z s;;
  let three = fun z s -> succ two z s;;
  ...
  let rec infty = fun z s -> let s' = s () in s' (infty z s);;

  let eq m n = m (fun () 
  let add m n = m n (fun () -> succ);;
  let print_num n = n () (fun () -> print_string "1"; fun _ -> ());;

  # print_num one;;
  1- : unit = ()
  # print_num (add two three);;
  11111- : unit = ()
  # print_num infty;;
  111111111111111111111111111111111111111111111111111111111111111111111111
  111111111111111111111111111111111111111111111111111111111111111111111111
  111111111111111111111111111111111111111111111111111111111111111111111111
  11111111111111111111Interrupted.
  # print_num (succ infty);;
  111111111111111111111111111111111111111111111111111111111111111111111111
  111111111111111111111111111111111111111111111111111111111111111111111111
  111111111111111111111111111111111111111111111111111111111111111111111111
  111111111111111111111Interrupted.

P.S.: When I started writing this, I thought Pierre's post was in jest. Now
I'm not so sure anymore...!

-- 
Frank Atanassow, Information & Computing Sciences, Utrecht University
Padualaan 14, PO Box 80.089, 3508 TB Utrecht, Netherlands
Tel +31 (030) 253-3261 Fax +31 (030) 251-379
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr