Strict extension does not make monadic bindings strict
The following two programs are not equivalent with respect to the strictness of readFile:
{-# LANGUAGE BangPatterns #-}
module Main where
main = do
!contents <- readFile "foo.txt"
print contents
And:
{-# LANGAUGE Strict #-}
module Main where
main = do
contents <- readFile "foo.txt"
print contents
Inspecting GHC Core for these two programs suggests that
!contents <- readFile "foo.txt"
is not equivalent to (with Strict enabled):
contents <- readFile "foo.txt"
Here's core using BangPatterns:
(readFile (unpackCString# "foo.txt"#))
(\ (contents_asg :: String) ->
case contents_asg of contents1_Xsk { __DEFAULT ->
print @ String $dShow_rYy contents1_Xsk
})
Here's core using Strict:
(readFile (unpackCString# "foo.txt"#))
(\ (contents_asg :: String) ->
print @ String $dShow_rYv contents_asg)
Does this core align with the design of the Strict extension? If it does, are users going to understand that using Strict is going to make let/where bindings strict, but is not going to make >>= bindings strict?
However, this is likely to just be a bug. At least, Johan Tibell and Adam Sandberg Eriksson, the designers and implementers of the Strict extension, believe this to be a bug:
Johan Tibell @ Thu Dec 10 14:34:39 UTC 2015 writes:
I believe this is just a bug, since the desugaring ought to be strict in the \x.
https://mail.haskell.org/pipermail/ghc-devs/2015-December/010747.html
Adam Sandberg Eriksson @ Thu Dec 10 15:26:17 UTC 2015 writes:
I agree that this seems to be a bug. I have a lot to do currently, but might be able to look at it sometime during next week.
https://mail.haskell.org/pipermail/ghc-devs/2015-December/010749.html
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.11 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler (CodeGen) |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |