On Fri, 5 Jan 2007, Jeremy Shaw wrote:

The easiest solution is to make things a little more strict. For
example, if you change:

nth i (x:xs) = if i < 0 then Empty else nth (i-1) xs

Even better, if I define:

nth 0 (x:_) = Just x
nth i (_:xs) = if i < 0 then Nothing else nth (i-1) xs
nth i [] = Nothing

makelist i = i `seq` i : (makelist (i+1))

nth 10000000 (makelist 1)

This works like a charm.  Thanks.

Brian

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to