Morning
Good Morning!
!månmån¡
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
here is a blog post that might do a better job https://eli.thegreenplace.net/2018/return-type-polymorphism-in-haskell/
yep, i think that explains it @danstone - so the return
impl from the IO monad is chosen because the return type of each step function is inferred to be IO String
Morning
morning
@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
mogge