
Is there a way to pattern match to a list argument and get a list? For example, I have this:
-- A LayoutItem has a center position (point), and the four ints are -- "left width", "rigth width", "top height", and "bottom height" data LayoutItem = LayoutItem Point Int Int Int Int deriving Show
-- This computes the left width of a group of composited LayoutItem. compositeLeftWidth :: [LayoutItem] -> Int compositeLeftWidth items = let itemsPosX = [ x | LayoutItem (Point (x,_)) _ _ _ _ <- items ] itemsLW = [ lw | LayoutItem _ lw _ _ _ <- items ] z = zipWith (\x y -> x-y+1) itemsPosX itemsLW in (minimum z) - 1
What I'm wondering is if I could somehow do something like
compositeLeftWidth [ LayoutItem Point( x, _ ) lw _ _ _ ] = ...
and that x and lw would each be the lists I'm calling itemsPosX and itemsLW above.
Thanks, Mike
That would be neat :-). But IIRC there is no syntax for that. However, if you are interested in other suggestions (by a very newbie, so
2009/3/27 Michael Mossey