Last active
August 28, 2020 22:57
-
-
Save nuttycom/72446e17d415bb2640d72a8814096bd6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes #-} | |
import Control.Monad (join) | |
sendBoth | |
:: (Monad m, Applicative n) | |
=> (forall a. a -> m ()) | |
-> (forall a. m a -> n a) | |
-> (forall a. n a -> m a) | |
-> m a | |
-> m b | |
-> (a -> c) | |
-> (a -> b -> d) | |
-> m () | |
sendBoth postToTwitter mn nm ma mb g h = | |
join . nm $ | |
(\a b -> postToTwitter $ h a b) | |
<$> mn ((\a -> nm (mn (postToTwitter $ g a) *> pure a)) =<< ma) | |
<*> mn mb | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE TupleSections #-} | |
import Control.Monad (join) | |
sendBoth | |
:: (Monad m, Applicative n) | |
=> (forall a. (() -> a) -> n a) | |
-> (forall a. m a -> n a) | |
-> (forall a. n a -> m a) | |
-> m a | |
-> m b | |
-> (a -> c) | |
-> (a -> b -> d) | |
-> (b -> e) | |
-> m (c, d, e) | |
sendBoth async mn nm ma mb g h i = | |
join . nm $ (\(nc, a) (ne, b) -> nm $ (,,) <$> nc <*> async (\_ -> h a b) <*> ne) | |
<$> ((\a -> (async (\_ -> g a), a)) <$> mn ma) | |
<*> ((\b -> (async (\_ -> i b), b)) <$> mn mb) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE TupleSections #-} | |
import Control.Monad (join) | |
sendBoth | |
:: forall m n a b c d e | |
. (Monad m, Applicative n) | |
=> (forall x. (() -> x) -> m (n x)) | |
-> (forall x. m x -> n x) | |
-> (forall x. n x -> m x) | |
-> m a | |
-> m b | |
-> (a -> c) | |
-> (a -> b -> d) | |
-> (b -> e) | |
-> m (c, d, e) | |
sendBoth async mn nm ma mb g h i = do | |
((nc, a), (ne, b)) <- nm ( | |
(,) <$> mn ((\a -> (,a) <$> async (\_ -> g a)) =<< ma) | |
<*> mn ((\b -> (,b) <$> async (\_ -> i b)) =<< mb) | |
) | |
nd <- async (\_ -> h a b) | |
nm $ (,,) <$> nc <*> nd <*> ne |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm really being made to work for this! In this third installment,
n
represents the ability to wait for the completion of the evaluation of an asynchronous computation.