Last active
September 20, 2017 14:56
-
-
Save commandodev/87656bd13f277e19654cef8374e7a16b to your computer and use it in GitHub Desktop.
This file contains 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
insert | |
:: (KnownSymbol k, Typeable i, ChannelType k api ~ i) | |
=> Proxy api -> Proxy k -> f i -> RouteMap f routes -> RouteMap f ((k :> i) ': routes) | |
insert _ pKey i = Routes . Map.insert k (I i) . unRoutes | |
where | |
k = (symbolVal pKey) ^. packed | |
type family Chan (chan :: *) :: * where | |
Chan (chan :> a) = a | |
-------------------------------------------------------------------------------- | |
class Channels api where | |
type Chans api :: [*] | |
mkChannels :: Proxy api -> IO (RouteMap Input (Chans api), RouteMap Output (Chans api)) | |
instance (KnownSymbol chan, Typeable a, Chan a ~ ty) => Channels (chan :> a) where | |
type Chans (chan :> a) = '[chan :> (Chan (chan :> a))] | |
mkChannels pApi = do | |
(o :: Output a, i :: Input a) <- spawn unbounded | |
let inp = insert pApi pK i emptyRoutes -- :: RouteMap Input '[chan :> a] | |
out = insert pApi pK o emptyRoutes | |
return (inp, out) -- insert pApi pK o emptyRoutes | |
where pK = Proxy :: Proxy chan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment