Is there a built-in function with signature :: (Monad m) => m a -> a ?
Hoogle tells that there is no such function.
Can you explain why?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
A monad only supplies two functions:
Both of these return something of type
m a, so there is no way to combine these in any way to get a function of typeMonad m => m a -> a. To do that, you’ll need more than these two functions, so you need to know more aboutmthan that it’s a monad.For example, the
Identitymonad hasrunIdentity :: Identity a -> a, and several monads have similar functions, but there is no way to provide it generically. In fact, the inability to “escape” from the monad is essential for monads likeIO.