[Haskell-cafe] arr considered harmful
pumpkingod at gmail.com
Tue Nov 1 01:44:31 CET 2011
Have you seen Adam Megacz's work on generalized arrows? I think he proposes
to kill arr and has done a decent amount of work on it.
On Mon, Oct 31, 2011 at 8:33 PM, Ryan Ingram <ryani.spam at gmail.com> wrote:
> I know it's a bit of an 'intentionally provocative' title, but with the
> recent discussions on Arrows I thought it timely to bring this up.
> Most of the conversion from arrow syntax into arrows uses 'arr' to move
> components around. However, arr is totally opaque to the arrow itself, and
> prevents describing some very useful objects as arrows.
> For example, I would love to be able to use the arrow syntax to define
> objects of this type:
> data Circuit a b where
> Const :: Bool -> Circuit () Bool
> Wire :: Circuit a a
> Delay :: Circuit a a
> And :: Circuit (Bool,Bool) Bool
> Or :: Circuit (Bool,Bool) Bool
> Not :: Circuit Bool Bool
> Then :: Circuit a b -> Circuit b c -> Circuit a c
> Pair :: Circuit a c -> Circuit b d -> Circuit (a,b) (c,d)
> First :: Circuit a b -> Circuit (a,c) (b,c)
> Swap :: Circuit (a,b) (b,a)
> AssocL :: Circuit ((a,b),c) (a,(b,c))
> AssocR :: Circuit (a,(b,c)) ((a,b),c)
> Loop :: Circuit (a,b) (a,c) -> Circuit b c
> Then we can have code that examines this concrete data representation,
> converts it to VHDL, optimizes it, etc.
> However, due to the presence of the opaque 'arr', there's no way to make
> this type an arrow without adding an 'escape hatch'
> Arr :: (a -> b) -> Circuit a b
> which breaks the abstraction: circuit is supposed to represent an actual
> boolean circuit; (Arr not) is not a valid circuit because we've lost the
> information about the existence of a 'Not' gate.
> The arrow syntax translation uses arr to do plumbing of variables. I
> think a promising project would be to figure out exactly what plumbing is
> needed, and add those functions to a sort of 'PrimitiveArrow' class. All
> of these plumbing functions are trivially implemented in terms of 'arr',
> when it exists, but if it doesn't, it should be possible to use the arrow
> syntax regardless.
> -- ryan
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe