`[<<][meta][>>][..]`
Sun Feb 14 20:58:10 CET 2010

## Commutative manipulations

```-- The idea is to locally unpack Term -> CTerm, perform a
-- simplification, and convert back to Term.

-- Commuative reduction is able to propagate ``literal bubbles to the
-- surface'' by keeping terms in a (L a :<*>: b) form.

data CTerm l t = U                              -- unit
| Z                              -- zero
| L l                            -- literal
| T t                            -- opaque term
| (CTerm l t) :<*>: (CTerm l t)  -- op

commOp :: (Num l) => (l -> l -> l) -> CTerm l t -> CTerm l t -> CTerm l t

commOp op = try (try (:<*>:)) where
(*) = op
try next = (<*>) where
Z <*> a = Z
U <*> a = a
L a <*> L b = L (a * b)                                          -- e
L a <*> (L b :<*>: c) = L (a * b) :<*>: c                        -- ae
(L a :<*>: b) <*> (L c :<*>: d) = L (a * c) :<*>: (b :<*>: d)    -- aec
a <*> (L b :<*>: c) = L b :<*>: (a :<*>: c)                      -- an
L a <*> b = L a :<*>: b                                          -- n
a <*> b = b `next` a

```
`[Reply][About]`
`[<<][meta][>>][..]`