dtgee
dtgee

Reputation: 1272

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.

Upvotes: 6

Views: 151

Answers (1)

sepp2k
sepp2k

Reputation: 370102

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.

Upvotes: 8

Related Questions