Article View: comp.lang.functional
Article #575Re: Is efficient backtracking feasible in functional languages?
From: John van Groningen
Date: Thu, 12 Nov 1992 17:03
Date: Thu, 12 Nov 1992 17:03
41 lines
1748 bytes
1748 bytes
In article <1992Nov10.164456.18062@email.tuwien.ac.at> Ulrich Neumerkel
E185/1 +43158801/4477, ulrich@mips.complang.tuwien.ac.at writes:
>strangesucc n = hd [x|x<-[0..];x>n];
>
>This program should run in constant space and linear time [1].
>However, for the implementations I tried, it turns out that the program
>seems to run in linear space! For a small n as 10000 the program aborts
>due to memory problems. Also a rewriting of the program to encode list
>comprehensions explicitly did not yield the desired result.
The following rewrite yields the desired result in constant space
in Haskell B:
main = print (h::Integer)
hd (e:l) = e
g n = n : g (n+1)
f [] n = []
f (x:v) n = if (x>n)
then (x:f v n)
else (f v n)
h :: Integer
h = hd (f (g 0) 1000000)
But if you change the function 'main' to:
main = print (hd (f (g 0) 1000000)::Integer)
the program runs in linear space !
>Is there ANY implementation of a lazy functional language to execute
>the program above in an efficient manner (i.e. in constant space)?
Yes, Chalmers LML implementation.
John van Groningen
Technical Details
Message-ID:
<BxM4q9.Jos@sci.kun.nl>Path:
arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!sci.kun.nl!mac1p.cs.kun.nl!johnvgReferences:
<1992Nov10.164456.18062@email.tuwien.ac.at>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.functional Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!sci.kun.nl!mac1p.cs.kun.nl!johnvg From: John van Groningen <johnvg@cs.kun.nl> Subject: Re: Is efficient backtracking feasible in functional languages? Message-ID: <BxM4q9.Jos@sci.kun.nl> X-Xxmessage-Id: <A7284C6E630120D7@mac1p.cs.kun.nl> X-Xxdate: Thu, 12 Nov 92 18:01:18 GMT Sender: news@sci.kun.nl (NUnet News Owner) Organization: University of Nijmegen X-Useragent: Nuntius v1.1.1d9 References: <1992Nov10.164456.18062@email.tuwien.ac.at> Date: Thu, 12 Nov 1992 17:03:44 GMT Lines: 41