Exit Monad IO

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:

{-# LANGUAGE MagicHash #-}

import GHC.Magic(runRW#)
import GHC.Types(IO(..))

hiddenPrint :: ()
hiddenPrint = case putStrLn "Hello !" of
  IO sideEffect -> case runRW# sideEffect of
    _ -> ()

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)?

+4
source share
2 answers

Safe Haskell. {-# Safe #-} , , , {-# Trustworthy #-}. .

+7

, Haskell. , , . :

  • GHC .
  • FFI C ,
  • unsafePerformIO
  • unsafeCoerce
  • Ptr a ,
  • Typeable , cast. ( GHC )

. , , - , , " , , ". , - , , , .

+3

Source: https://habr.com/ru/post/1654205/


All Articles