Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- return <=< x = x
- seq (return <=< undefined :: a -> Identity b) () = ()
- seq (undefined :: a -> Identity b) () = undefined
- seq (return <=< undefined :: a -> Maybe b) () = ()
- seq (undefined :: a -> Maybe b) () = undefined
- -- in GHC.Types (ghc-prim)
- newtype IO a = IO (State# RealWorld -> (# State# RealWorld, a #))
- -- in GHC.Base (base)
- instance Monad IO where
- {-# INLINE return #-}
- {-# INLINE (>>) #-}
- {-# INLINE (>>=) #-}
- m >> k = m >>= _ -> k
- return = returnIO
- (>>=) = bindIO
- fail s = failIO s
- returnIO :: a -> IO a
- returnIO x = IO $ s -> (# s, x #)
- bindIO :: IO a -> (a -> IO b) -> IO b
- bindIO (IO m) k = IO $ s -> case m s of (# new_s, a #) -> unIO (k a) new_s
- thenIO :: IO a -> IO b -> IO b
- thenIO (IO m) k = IO $ s -> case m s of (# new_s, _ #) -> unIO k new_s
- unIO :: IO a -> (State# RealWorld -> (# State# RealWorld, a #))
- unIO (IO a) = a
- return x >>= f ≡ f x:
- return x >>= f = IO $ s -> case (t -> (# t, x #)) s of
- (# new_s, a #) -> unIO (f a) new_s
- = IO $ s -> case (# s, x #) of
- (# new_s, a #) -> unIO (f a) new_s
- = IO $ s -> unIO (f x) s
- m >>= return ≡ m:
- (IO k) >>= return = IO $ s -> case k s of
- (# new_s, a #) -> unIO (return a) new_s
- = IO $ s -> case k s of
- (# new_s, a #) -> (t -> (# t, a #)) new_s
- = IO $ s -> case k s of
- (# new_s, a #) -> (# new_s, a #)
- = IO $ s -> k s
- m >>= (x -> g x >>= h) ≡ (m >>= g) >>= h:
- (IO k) >>= (x -> g x >>= h) = IO $ s -> case k s of
- (# new_s, a #) -> unIO ((x -> g x >>= h) a) new_s
- = IO $ s -> case k s of
- (# new_s, a #) -> unIO (g a >>= h) new_s
- = IO $ s -> case k s of
- (# new_s, a #) -> (t -> case unIO (g a) t of
- (# new_t, b #) -> unIO (h b) new_t) new_s
- = IO $ s -> case k s of
- (# new_s, a #) -> case unIO (g a) new_s of
- (# new_t, b #) -> unIO (h b) new_t
- ((IO k) >>= g) >>= h = IO $ s -> case (t -> case k t of
- (# new_s, a #) -> unIO (g a) new_s) s of
- (# new_t, b #) -> unIO (h b) new_t
- = IO $ s -> case (case k s of
- (# new_s, a #) -> unIO (g a) new_s) of
- (# new_t, b #) -> unIO (h b) new_t
- case (case e of case e of
- pat1 -> ex1) of ≡ pat1 -> case ex1 of
- pat2 -> ex2 pat2 -> ex2
- m >>= return ≡ m
- Prelude> seq ( undefined >>= return :: IO () ) "hello, world"
- "hello, world"
- Prelude> seq ( undefined :: IO () ) "hello, world"
- *** Exception: Prelude.undefined
- Prelude> seq ( undefined >>= return :: Maybe () ) "hello, world"
- *** Exception: Prelude.undefined
- Prelude> seq ( undefined :: Maybe () ) "hello, world"
- *** Exception: Prelude.undefined
Add Comment
Please, Sign In to add comment