How to show 100% full sugarless function in Haskell?

Viewed 96

For example, say putStrLn "one" >> putStrLn "two". If I do :info >>, I see this:

type Monad :: (* -> *) -> Constraint
class Applicative m => Monad m where
  ...
  (>>) :: m a -> m b -> m b
  ...
    -- Defined in ‘GHC.Base’
infixl 1 >>

I would like to see what the expression putStrLn "one" >> putStrLn "two" is, replacing >> with this definition. But not just for this function expression, but any function expression, how to find and print the sugarless version.

1 Answers

(>>) is a function, and functions generally aren't considered sugar, even if they're from typeclasses. But anyway, in the expression putStrLn "one" >> putStrLn "two", it comes from the IO monad, so its definition will be inside of instance Monad IO. It happens to be (*>) which is itself thenIO, which is this:

thenIO :: IO a -> IO b -> IO b
thenIO (IO m) k = IO (\ s -> case m s of (# new_s, _ #) -> unIO k new_s)

Note that this uses parts of IO that aren't public API, so this isn't really something that you could write yourself in a normal program.

Related