3 ms·
Do you have a concrete example using Concurrently where the effect semantics is harder to understand--possibly even misleading--with effect combinators than wit
by throwway262515 6mo ago
Do you have a concrete example using Concurrently where the effect semantics is harder to understand--possibly even misleading--with effect combinators than with do notation?
- kccqzy 6mo agoWhen you use Concurrently you are implying that you want things to happen concurrently and you don’t care about effect ordering. You leave the effect ordering to the GHC runtime in how it schedules these green threads. Using do notation here works but it is slightly misleading. A seasoned Haskeller would never see do notation and assume anything about the ordering of effects.
- tome 6mo agoHere's a silly but simple example: newtype FlippedIO a = MkFlippedIO { runFlippedIO :: IO a } deriving Functor instance Applicative FlippedIO where pure = MkFlippedIO . pure liftA2 f (MkFlippedIO x) (MkFlippedIO y) = MkFlippedIO ((flip . liftA2 . flip) f x y) data Person = Person String String deriving Show putStrLnFlipped = MkFlippedIO . putStrLn getLineFlipped = MkFlippedIO getLine getPerson :: IO Person getPerson = runFlippedIO $ Person <$> (putStrLnFlipped "Enter your first name:" *> getLineFlipped) <*> (putStrLnFlipped "Enter your last name:" *> getLineFlipped) It runs things "backwards": ghci> getPerson One Enter your last name: Two Enter your first name: Person "Two" "One"