Thanks for the help on Stackoverflow today! I've really been enjoying getting to know your library, and in conjunction, learning tradeoffs between your approach and that of Conal Elliot in concat
, namely, his objects look more like type Object k :: * -> Constraint
. (If you know of any literature, discussion group threads etc on the tradeoffs between the 2 approaches, please let me know!)
Anyway, I wanted to share an extension to Agent
s I've been playing around with that makes it act a little more like proc syntax, namely, allowing for tuples of GenericAgent
s. It's messy, I could probably simplify it, but, it works!:
type O4 p a b c d = (Object p a, Object p b, Object p c, Object p d)
type O6 p a b c d e f = (Object p a, Object p b, Object p c, Object p d, Object p e, Object p f)
-- | Interpret tuples of 'GenericAgent' as just a 'GenericAgent'.
class AgentParam p q b where
type AgentParamC p q b :: Constraint
type AgentParamOutTy p q b
agentParam :: AgentParamC p q b => b -> GenericAgent p q (AgentParamOutTy p q b)
instance AgentParam p q (GenericAgent p q a1, GenericAgent p q a2) where
type AgentParamC p q (GenericAgent p q a1, GenericAgent p q a2)
= (O4 p q a1 a2 (a1, a2), PairObjects p a1 a2, PreArrow p)
type AgentParamOutTy p q (GenericAgent p q a1, GenericAgent p q a2)
= (a1, a2)
agentParam (x, y) = GenericAgent (runGenericAgent x &&& runGenericAgent y)
instance AgentParam p q (GenericAgent p q a1, GenericAgent p q a2, GenericAgent p q a3) where
type AgentParamC p q (GenericAgent p q a1, GenericAgent p q a2, GenericAgent p q a3) =
(O6 p q a1 a2 a3 (a2, a3) (a1, (a2, a3)), PairObjects p a2 a3, PairObjects p a1 (a2, a3), PreArrow p)
type AgentParamOutTy p q (GenericAgent p q a1, GenericAgent p q a2, GenericAgent p q a3) =
(a1, (a2, a3))
agentParam (x, y, z) = GenericAgent (runGenericAgent x &&& runGenericAgent y &&& runGenericAgent z)
-- | Arrow-like interface
f $-< x = f $~ agentParam x -- hm... this is tough to type
This allows syntax like:
let out = SomeArr <<< WowArr $-< (x, y)
vs
proc ... out <- SomeArr <<< WowArr -< (x, y)
This allows tupling on the input side. Then on the output side, it'd be nice if we could pattern match, like proc
syntax can, so, I'm wondering if I could do something with PatternSynonym
s there too, but, haven't gotten around to it yet.
Anyway, just wanted to let you know, and if this is interesting or deserves pursuit, lmk, I'd be happy to contribute a PR!