writing a function to build a list of ints from user input

Galen Menzel galen@alumni.utexas.net
Tue, 6 May 2003 12:26:38 -0500


On Tue, May 06, 2003 at 08:14:46AM -0500, Galen Menzel wrote:
> On Tue, May 06, 2003 at 07:22:20AM -0400, David Roundy wrote:
> > On Tue, May 06, 2003 at 05:02:56AM -0500, Galen Menzel wrote:
> > > 
> > > makeList :: IO [Int]
> > > makeList = do s <- getLine
> > > 	      case read s of
> > > 		0 -> return []
> > > 		x -> do xs <- makeList
> > > 			return (x:xs)
> > > 
> > > I changed the if to a case so that (read s) doesn't get called twice.
> > 
> > Does the compiler not optimize away identical calls? Or is it not allowed
> > to, for some reason?
> 
> This is certainly possible, particularly with a referentially
> transparent language.  There's a technique called memoization that
> ...

Hmm... Looks like I was confusing memoization with common-
subexpression elimination.

Sorry!
galen