[Haskell-cafe] A law for MonadReader

Viktor Dukhovni ietf-dane at dukhovni.org
Sun Jun 3 07:46:56 UTC 2018



> On Jun 3, 2018, at 3:32 AM, Benjamin Fox <foxbenjaminfox at gmail.com> wrote:
> 
> Here is the counterexample:
> 
> instance MonadReader (IORef Int) IO where
>     ask = newIORef 0
>     local _ = id
> 
> This obeys law (1): (newIORef 0 >> newIORef 0) == newIORef 0.

Can you explain what you mean?

Prelude> :m + Data.IORef
Prelude Data.IORef> let z = 0 :: Int
Prelude Data.IORef> a <- newIORef z
Prelude Data.IORef> b <- newIORef z
Prelude Data.IORef> let c = newIORef z
Prelude Data.IORef> let d = newIORef z
Prelude Data.IORef> a == b
False
Prelude Data.IORef> c == d

<interactive>:8:1: error:
    • No instance for (Eq (IO (IORef Int))) arising from a use of ‘==’
    • In the expression: c == d
      In an equation for ‘it’: it = c == d

-- 
	Viktor.



More information about the Haskell-Cafe mailing list