Fork me on GitHub
#clojure-uk
<
2020-09-30
>
dharrigan05:09:14

Good Morning!

mccraigmccraig06:09:44

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 ?

wotbrew08:09:41

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

mccraigmccraig08:09:45

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

mccraigmccraig08:09:28

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

wotbrew08:09:51

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.

wotbrew08:09:59

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

mccraigmccraig09:09:24

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

alexlynham08:09:05

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

alexlynham08:09:23

somebody more knowledgeable should prob answer tho haha