12.07.2015 Views

CSCE 314 Programming Languages - TAMU Computer Science ...

CSCE 314 Programming Languages - TAMU Computer Science ...

CSCE 314 Programming Languages - TAMU Computer Science ...

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Laziness with RecursionRecursion combined with lazy evaluation can be tricky;stack overflows may result in the following example:expensiveLen [] = 0expensiveLen (_:xs) = 1 + expensiveLen xsstillExpensiveLen ls = len 0 lswhere len z [] = zcheapLen ls = len 0 lslen z (_:xs) = len (z+1) xswhere len z [] = zlen z (_:xs) = let z’ = z+1in z’ `seq` len z’ xs> expensiveLen [1..10000000] -- takes quite long> stillExpensiveLen [1..10000000] -- also takes long> cheapLen [1..10000000] -- less memory and time44

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!