One of the things that I like most about Haskell is how the compiler detects side effects through the IO monad in function signatures. However, it seems easy to get around this type check by importing 2 GHC primitives:
{-
import GHC.Magic(runRW
import GHC.Types(IO(..))
hiddenPrint :: ()
hiddenPrint = case putStrLn "Hello !" of
IO sideEffect -> case runRW
_ -> ()
hiddenPrinthas a unit type, but when called, it causes a side effect (it prints Hello). Is there a way to ban these hidden IOs (except that no one imports GHC primitives)?
source
share