<div dir="ltr"><div>Are the following two programs equivalent with respect to the strictness</div><div>of `readFile`?</div><div><br></div><div>--8<---------------cut here---------------start------------->8---</div><div>{-# LANGUAGE BangPatterns #-}</div><div><br></div><div>module Main where</div><div><br></div><div>main = do</div><div>  !contents <- readFile "foo.txt"</div><div>  print contents</div><div>--8<---------------cut here---------------end--------------->8---</div><div><br></div><div>And:</div><div><br></div><div>--8<---------------cut here---------------start------------->8---</div><div>{-# LANGAUGE Strict #-}</div><div><br></div><div>module Main where</div><div><br></div><div>main = do</div><div>  contents <- readFile "foo.txt"</div><div>  print contents</div><div>--8<---------------cut here---------------end--------------->8---</div><div><br></div><div>The documentation on "Strict-by-default pattern bindings" gives</div><div>let/where binding as an example, but there is not a monadic bind example.</div><div><a href="http://downloads.haskell.org/~ghc/master/users-guide/glasgow_exts.html#strict-by-default-pattern-bindings">http://downloads.haskell.org/~ghc/master/users-guide/glasgow_exts.html#strict-by-default-pattern-bindings</a></div><div><br></div><div>Inspecting GHC Core for these two programs suggests that</div><div><br></div><div>!contents <- readFile "foo.txt"</div><div><br></div><div>is not equivalent to (with Strict enabled):</div><div><br></div><div>contents <- readFile "foo.txt"</div><div><br></div><div>Here's core using BangPatterns:</div><div><br></div><div>(readFile (unpackCString# "foo.txt"#))</div><div>(\ (contents_asg :: String) -></div><div>   case contents_asg of contents1_Xsk { __DEFAULT -></div><div>   print @ String $dShow_rYy contents1_Xsk</div><div>   })</div><div><br></div><div>Here's core using Strict:</div><div><br></div><div>(readFile (unpackCString# "foo.txt"#))</div><div>(\ (contents_asg :: String) -></div><div>   print @ String $dShow_rYv contents_asg)</div><div><br></div><div>Does this core align with the design of the Strict extension?</div><div><br></div><div>If it does, are users going to understand that using Strict is going to</div><div>make let/where bindings strict, but is not going to make <- or >>=</div><div>bindings strict?</div><div><br></div><div>--</div><div>Rob Stewart</div></div>