plaidfinch / strictcheck Goto Github PK
View Code? Open in Web Editor NEWKeep your laziness in check!
Home Page: https://hackage.haskell.org/package/StrictCheck.
License: MIT License
Keep your laziness in check!
Home Page: https://hackage.haskell.org/package/StrictCheck.
License: MIT License
What do you think of adding an instance of Show
for Demand a
(or (%)
if you prefer) so that we can simply write this:
> observe (`seq` ()) (&&) False False
(False,False :* _ :* Nil)
I find it quite convenient for doing small experiments in ghci. I have this instance as a quick hack but you may know a better implementation:
instance Shaped a => Show (Demand a) where
show = prettyDemand
An alternative proposal is to have specialized functions to print the output of observe
and variants, or a variant of observe
that prints in addition to/instead of returning the demand.
I was just reading your paper and when reading about entangle
and observe
I thought that there was a good chance, that memorization would cause observe
to use the same entangled value twice, thus giving false results.
Indeed I found the following program, where that seems to be the case:
{-# LANGUAGE GADTs #-}
import Test.StrictCheck
import Data.Foldable (traverse_)
import Data.Bifunctor (bimap)
main :: IO ()
main =
(print . bimap prettyDemand (\(x :* Nil) -> prettyDemand x)) `traverse_` [
observe (\() -> ()) (\() -> ()) (),
observe (\() -> ()) (\_ -> ()) ()
]
I would expect the following output:
("()","()")
("()","_")
This matches the actual output for ghc versions 8.2.2 and 8.4.3 with any optimisation level as well as ghc-8.6.1 with -O0
. However when compiling with ghc-8.6.1 and -O1
or -O2
the actual output is this:
("()","()")
("()","()")
Even worse, when we change the order of the two observe
-calls in the list we get this:
("()","_")
("()","_")
I think the best way to fix this would be to change entangle
to this safe (exportable) version:
entangle :: a -> IO (a, IORef (Thunk a))
entangle = do
ref <- newIORef Thunk
return ( unsafePerformIO $ do
writeIORef ref (Eval a)
return a
, ref )
This version of entangle should be referentially transparent and allows the user to observe the evaluation status of the entangled value at different points in time. Furthermore, and most importantly for this issue, leaving out the outer unsafePerformIO
makes sure that two calls to entangle
will create two different entangled values with two different IORef
s, thus making bugs like this impossible. However this of cause would probably require a lot of code to be rewritten to accommodate for the new type and maybe there is a quick and dirty solution that somehow prevents memorization or even not exporting observe and making sure it is only used in safe ways.
Via /u/Tarmen, we have a bug report posted on Reddit. The relevant piece seems to be:
...on windows the error reporting breaks with
*** Failed! Falsifiable (after 15 tests and 6 shrinks): ┌──────────────┐ ┌─────────────────────┐ │ Inputs ├───┤ Demand on result │ ├──────────────┤ ├─────────────────────┤ │ StrictCheckTest.EXE: <stdout>: commitBuffer: invalid argument (invalid character)
I suspect this is due to issues with Unicode text handling. The crash occurs right before StrictCheck would ordinarily print the Unicode bullet character •
(U+2022).
A search of bug reports seems to indicate this is a locale issue, in particular this StackOverflow answer says that this issue might be resolved by runningsetLocaleEncoding utf8
before printing text. It references the documentation for GHC.IO.Encoding
, as noted in part of the Hakyll FAQ.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.