[Yhc] instance Monad IO bug
Bernie Pope
bjpop at csse.unimelb.edu.au
Sun Mar 11 08:10:43 EDT 2007
> for a file
> main = print "hi" >> return undefined >> print "bye"
> ghc, hugs and nhc98 print
> "hi"
> "bye"
> yhc prints
> "hi"
> Prelude.undefined
That is strange.
In my version of Yhc it works as expected (same as Hugs and
GHC).
The instance of IO for Monad in my version is:
\begin{code}
instance Monad IO where
x >>= y = IO (primBind1 x y)
where
primBind1 (IO xf) y w =
case xf w of
Right xv -> case y xv of
IO yv -> yv w
Left err -> Left err -- Changing type
x >> y = IO (primBind2 x y)
where
primBind2 (IO xf) y w =
case xf w of
Right xv -> case y of
IO yv -> yv w
Left err -> Left err -- Changing type
return a = IO (primReturn a)
where
primReturn a w = Right a
\end{code}
To my eyes there is no strictness problem in this
definition.
Also, in my version IO is defined this way:
\begin{code}
data World = World
newtype IO a = IO (World -> Either IOError a)
\end{code}
>From memory this is the same as it was in nhc98.
I haven't done a darcs pull for a week or so; perhaps my
version is older than yours?
Cheers,
Bernie.
More information about the Yhc
mailing list