There is no exception when defining a lazy field until you print it.
> data T = T Int deriving (Show)
> let t = T undefined
> t
T *** Exception: Prelude.undefined
CallStack (from HasCallStack):
error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
undefined, called at <interactive>:3:7 in interactive:Ghci3
With a strict field ( !Int), I thought that it undefinedwould be evaluated immediately, which would throw an exception, but in fact it would not be evaluated anyway before it was printed. Why is this?
> data X = X !Int deriving (Show)
> let x = X undefined
> x
*** Exception: Prelude.undefined
CallStack (from HasCallStack):
error, called at libraries/base/GHC/Err.hs:79:14 in base:GHC.Err
undefined, called at <interactive>:6:11 in interactive:Ghci5
source
share