16 Dec
2014
16 Dec
'14
2:59 a.m.
Using this combinator instead of writing the algorithm directly cost me 30% allocation overhead! What does your algorithm look like when you write it directly? Something like this:
flatten_many fmode roles tys = unzip `liftM` mapM go (zip roles tys) where go (Nominal,ty) = flatten_one (fmode { fe_eq_rel = NomEq }) ty go (Representational,ty) = flatten_one (fmode { fe_eq_rel = ReprEq }) ty go (Phantom, ty) = -- See Note [Phantoms in the flattener] return (ty, mkTcPhantomCo ty ty) ? Maybe this has something to do with `zipWithAndUnzipM` not being tail-recursive vs. direct version being able to fuse intermediate lists? Janek