StrictCheck-0.1.0: StrictCheck: Keep Your Laziness In Check

Safe HaskellNone
LanguageHaskell2010

Test.StrictCheck.Observe.Unsafe

Description

This module defines the underlying unsafe primitives StrictCheck uses to implement purely functional observation of evaluation.

The "functions" in this module are not referentially transparent!

Synopsis

Documentation

entangle :: forall a. a -> (a, Thunk a) Source #

From some value of any type, produce a pair: a copy of the original value, and a Thunk of that same type, with their values determined by the order in which their values themselves are evaluated

If the copy of the value is evaluated to weak-head normal form before the returned Thunk, then any future inspection of the Thunk will show that it is equal to the original value wrapped in an Eval. However, if the copy of the value is not evaluated by the time the Thunk is evaluated, any future inspection of the Thunk will show that it is equal to Thunk.

A picture may be worth 1000 words:

>>> x = "hello," ++ " world"
>>> (x', t) = entangle x
>>> x'
"hello, world"
>>> t
Eval "hello, world"
>>> x = "hello," ++ " world"
>>> (x', t) = entangle x
>>> t
Thunk
>>> x'
"hello, world"
>>> t
Thunk

entangleShape :: Shaped a => a -> (a, Demand a) Source #

Recursively entangle an a, producing not merely a Thunk, but an entire Demand which is piecewise entangled with that value. Whatever portion of the entangled value is evaluated before the corresponding portion of the returned Demand will be represented in the shape of that Demand. However, any part of the returned Demand which is evaluated before the corresponding portion of the entangled value will be forever equal to Thunk.

The behavior of this function is even more tricky to predict than that of entangle, especially when evaluation of the entangled value and the corresponding Demand happen at the same time. In StrictCheck, all evaluation of the entangled value occurs before any evaluation of the Demand; we never interleave their evaluation.