Fork me on GitHub

Good Morning!


anyone know enough haskell to tell me what feature/s it uses to determine which return implementation to call in a do? does it use the type of the required result ?


haskell has return polymorphism, so the return of functions can be left generic and the inference / type annotations can determine the type when it needs to be decided


right, but in that example the compiler has to figure out that the return impl to call is from the IO instance


(and i may well have the hsakell vocabulary completely screwed up... i've never used it in anger)


return sig is something like return :: (Monad M) => M a right. Because the do notation it sits in is typed IO the return type of M must be IO. Basically with return type polymorphism the compiler chooses the type that conforms with the surrounding code / signatures (or leaves generic if it can). It's a really cool feature that most mainstream type systems do not have.


I am definitely not an expert tho, its just my understanding as a haskell noob


yep, i think that explains it @U0GE2S1NH - so the return impl from the IO monad is chosen because the return type of each step function is inferred to be IO String


@mccraigmccraig that would be my guess, cos it must know the type as part of the bind


somebody more knowledgeable should prob answer tho haha