Why are there two calls to seq
in the code below (sourced from here) - r
is passed twice:
first' :: (a -> b) -> (a, c) -> (b, c)
first' f (x,y) = let { x' = f x; r = (x', y) }
in x' `seq` r `seq` r
I would think that one call to seq
would do the trick of making it strict.
If two sequences have equal priority, then the items from them are picked in a random order. SEQ_ARB_RANDOM: If this arbitration mode is selected, sequence items from different sequences are picked in a random order by ignoring all priorities.
SEQ_ARB_STRICT_RANDOM: This is similar to SEQ_ARB_RANDOM except that the priorities are NOT ignored. The items are picked randomly from sequences with highest priority first followed by next and in that order.
Implementing this lock system without any restrictions gives us the Simple Lock-based protocol (or Binary Locking ), but it has its own disadvantages, they do not guarantee Serializability. Schedules may follow the preceding rules but a non-serializable schedule may result. Attention reader! Don’t stop learning now.
It's a mistake at some level or other. r `seq` r
and r
are completely identical, semantically.
I'm fairly confident that it is a typo. I guess it should have been
first' :: (a -> b) -> (a, c) -> (b, c)
first' f (x,y) = let { x' = f x; r = (x', y) }
in x' `seq` y `seq` r
so that both pair components are forced. Or perhaps
first' :: (a -> b) -> (a, c) -> (b, c)
first' f (x,y) = let { x' = f x; r = (x', y) }
in x' `seq` r
which produces a fully evaluated pair, assuming that the second component was already evaluated. This is sensible, for instance, if all the operations we use that act on the IORef (Int, Int)
state preserve the invariant "both components must always be evaluated".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With