The difference between `Lazy.force` and` Lazy.force_val`

There are two forces in the Lazy module:


val force: 'at →' a

force x forces suspension x and returns its result. If x has already been forced, Lazy.force x returns the same value again without reprogramming it. If it raises an exception, then the same exception is raised again. Raise Undefined if forcing x tries to force x itself recursively.


val force_val: 'at →' a

force_val x forces suspension x and returns its result. If x has already been forced, force_val x returns the same value again without reprogramming it. Raise Undefined if forcing x tries to force x itself recursively. If evaluating x raises an exception, it is not indicated whether force_val x raises the same exception or Undefined.


Only difference seems to be

If evaluating x raises an exception, it is not indicated whether force_val x raises the same exception or Undefined.`

In my opinion, we do not know whether it will raise the original exception or Undefinedif we will use it force_val.

Then what's the point? Why so? Any good that we can get from force_val?

+4
source share
1 answer

I guess this is for performance. If you want to get the same error, use force. If you do not want to increase productivity, use force_val.

, force , force_val, .

, : force, , force_val , force_val force Undefined.

EDIT: , , force_val force , force - , force_val - .

+5

Source: https://habr.com/ru/post/1538063/


All Articles