Skip to content

Instantly share code, notes, and snippets.

@UnkindPartition
Created December 25, 2014 15:42
Show Gist options
  • Save UnkindPartition/62d5a4f8c25e493c6db1 to your computer and use it in GitHub Desktop.
Save UnkindPartition/62d5a4f8c25e493c6db1 to your computer and use it in GitHub Desktop.
{-# LANGUAGE
FlexibleInstances,
FlexibleContexts,
UndecidableInstances,
MultiParamTypeClasses,
GADTs,
ConstraintKinds,
ScopedTypeVariables,
TypeOperators
#-}
module Concurrently where
import Control.Applicative
import Control.Monad.Trans.Control
import Control.Concurrent.Async.Lifted.Safe
import Data.Constraint
import Data.Constraint.Forall
-- | @Pure m a@ is a synonym for @StM m a ~ a@
class (StM m a ~ a) => Pure m a
instance (StM m a ~ a) => Pure m a
data Concurrently m a where
Concurrently :: Forall (Pure m) => m a -> Concurrently m a
instance (Functor m) => Functor (Concurrently m) where
fmap f (Concurrently a) = Concurrently $ f <$> a
instance (MonadBaseControl IO m, Forall (Pure m)) => Applicative (Concurrently m) where
pure = Concurrently . pure
Concurrently (fs :: m (a -> b)) <*> Concurrently (as :: m a) =
(Concurrently $ uncurry ($) <$> concurrently fs as)
\\ (inst :: Forall (Pure m) :- Pure m a)
\\ (inst :: Forall (Pure m) :- Pure m (a -> b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment