Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
92478f77
Commit
92478f77
authored
Jan 17, 2008
by
twanvl
Browse files
Added Applicative instance for IOEnv
parent
acb70e7c
Changes
1
Hide whitespace changes
Inline
Side-by-side
compiler/utils/IOEnv.hs
View file @
92478f77
...
...
@@ -38,7 +38,7 @@ import Panic ( try, tryUser, tryMost, Exception(..) )
import
Data.IORef
(
IORef
,
newIORef
,
readIORef
,
writeIORef
)
import
System.IO.Unsafe
(
unsafeInterleaveIO
)
import
System.IO
(
fixIO
)
import
MonadUtils
----------------------------------------------------------------------
-- Defining the monad type
...
...
@@ -49,13 +49,17 @@ newtype IOEnv env a = IOEnv (env -> IO a)
unIOEnv
(
IOEnv
m
)
=
m
instance
Monad
(
IOEnv
m
)
where
(
>>=
)
=
thenM
(
>>
)
=
thenM_
return
=
returnM
fail
s
=
failM
-- Ignore the string
(
>>=
)
=
thenM
(
>>
)
=
thenM_
return
=
returnM
fail
s
=
failM
-- Ignore the string
instance
Applicative
(
IOEnv
m
)
where
pure
=
returnM
IOEnv
f
<*>
IOEnv
x
=
IOEnv
(
\
env
->
f
env
<*>
x
env
)
instance
Functor
(
IOEnv
m
)
where
fmap
f
(
IOEnv
m
)
=
IOEnv
(
\
env
->
fmap
f
(
m
env
))
fmap
f
(
IOEnv
m
)
=
IOEnv
(
\
env
->
fmap
f
(
m
env
))
returnM
::
a
->
IOEnv
env
a
returnM
a
=
IOEnv
(
\
env
->
return
a
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment