clojure-uk

A place for people in the UK, near the UK, visiting the UK, planning to visit the UK or just vaguely interested to randomly chat about things (often vi and emacs, occasionally clojure). More general the #ldnclj
jiriknesl 2020-09-30T04:49:33.072900Z

Morning

dharrigan 2020-09-30T05:48:14.073100Z

Good Morning!

mccraigmccraig 2020-09-30T06:04:50.073400Z

!månmån¡

mccraigmccraig 2020-09-30T06:14:44.074100Z

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 ?

wotbrew 2020-09-30T08:24:41.075600Z

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

mccraigmccraig 2020-09-30T08:31:45.075900Z

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

mccraigmccraig 2020-09-30T08:32:28.076100Z

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

wotbrew 2020-09-30T08:57:51.076500Z

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.

wotbrew 2020-09-30T08:59:59.076700Z

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

wotbrew 2020-09-30T09:01:07.077Z

here is a blog post that might do a better job https://eli.thegreenplace.net/2018/return-type-polymorphism-in-haskell/

mccraigmccraig 2020-09-30T09:49:24.077200Z

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

dominicm 2020-09-30T08:01:42.074800Z

Morning

alexlynham 2020-09-30T08:01:50.074900Z

morning

alexlynham 2020-09-30T08:02:05.075Z

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

alexlynham 2020-09-30T08:02:23.075100Z

somebody more knowledgeable should prob answer tho haha

thomas 2020-09-30T08:50:14.076400Z

mogge