Skip to content

Instantly share code, notes, and snippets.

@commandodev
Last active September 20, 2017 14:56
Show Gist options
  • Save commandodev/87656bd13f277e19654cef8374e7a16b to your computer and use it in GitHub Desktop.
Save commandodev/87656bd13f277e19654cef8374e7a16b to your computer and use it in GitHub Desktop.
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