How to extract value from monadic action

前端 未结 8 2301

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?<

8条回答
  •  遥遥无期
    2020-11-27 05:49

    Because it may make no sense (actually, does make no sense in many instances).

    For example, I might define a Parser Monad like this:

    data Parser a = Parser (String ->[(a, String)])
    

    Now there is absolutely no sensible default way to get a String out of a Parser String. Actually, there is no way at all to get a String out of this with just the Monad.

提交回复
热议问题