File: kitloop2.sml

package info (click to toggle)
mlton 20100608-5
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 36,624 kB
  • sloc: ansic: 18,441; lisp: 2,879; makefile: 1,572; sh: 1,326; pascal: 256; asm: 97
file content (30 lines) | stat: -rw-r--r-- 528 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
(*kitloop2.sml*)

(* A tail-recursive loop which gives stack overflow, unless one
   uses storage mode analsysis  *)

val x =
let 
  val N = 500
  val I = 1000

  type int_pair = int * int
  val maxint = 2000
  val zero = (0,0)
  fun is_zero(0,0) = true
    | is_zero _ = false

  fun sub (m,n) =
      if n=0 then (m-1, maxint)
      else (m, n-1)

  fun loop (x as (m,n)) =
      if is_zero x then x
      else loop(sub x)

  fun loop' p = (loop p; "\ndone\n")

in
  print "\nlooping...\n";
  print (loop'(maxint,maxint))
end