Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confirming lazy evaluation

I accidentally deleted my post, but I'm reposting this question for clarification.

If I have a function:
const x = 1

If I ask Haskell:
const (1/0)

It will return 1 because lazy evaluation doesn't actually calculate what 1/0 is, right? It doesn't need to.

like image 632
dtgee Avatar asked Mar 21 '13 21:03

dtgee


1 Answers

Yes, that's right. const, as you defined it, will always produce 1 when it is evaluated - no matter what the argument is. And since the argument is not relevant to the result, it is not evaluated. Thus any error or non-termination that might be caused by evaluating the argument will not occur.

like image 199
sepp2k Avatar answered Sep 19 '22 10:09

sepp2k