On Mon, 2011-06-06 at 23:38 +0800, Lyndon Maydwell wrote: > I'm writing an optimisation routine using Uniplate. Unfortunately, a > sub-function I'm writing is getting caught in an infinite loop because > it doesn't return Nothing when there are no optimisations left. > > I'd like a way to move the last Just into f, but this makes recursion > very messy. I was wondering if there was a nice way to use something > like the Monad or Applicative instance to help here. > > -- Sets of changes > o (Modifier (Changes []) i) = Just $ i > o (Modifier (Changes [c]) i) = Just $ Modifier c i > o (Modifier (Changes l) i) = Just $ Modifier (Changes (f l)) i > where > f (Scale x y : Scale x' y' : l) = f $ Scale (x*x') (y*y') : f > l > f (Translate x y : Translate x' y' : l) = f $ Translate (x+x') (y+y') : f > l > f (Rotate x : Rotate x' : l) = f $ Rotate (x+x') : f > l > f l = l > > > Any ideas?
Something like:
...
f (Rotate x : Rotate x' : l)
= Just $ f (Rotate (x+x') : fromMaybe l (f l))
f l = Nothing -- As far as I understend
Regards
signature.asc
Description: This is a digitally signed message part
_______________________________________________ Haskell-Cafe mailing list [email protected] http://www.haskell.org/mailman/listinfo/haskell-cafe
