[Haskell-beginners] pattern matching to data inside a list
mpm at alumni.caltech.edu
Fri Mar 27 09:25:43 EDT 2009
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
-- 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
PS Let me repeat my request to find out how to install SOE "on the
library path." I know I'm impatient about this, but it seems simple
enough, and it's driving me crazy that I can only write software in the
same directory where I've installed SOE.
More information about the Beginners