Hi,

using list comprehensions for the kind filter&map operation you're 
wanting to express, seems like a good option.

 border p = check "no border in page"  [ x | (Border x) <- p]
 margin p = check "no margin in page"  [ x | (Margin x) <- p]

 check :: String -> [a] -> a
 check err_msg []    = error err_msg -- game over.
 check err_msg (x:_) = x

--Sigbjorn

S. Alexander Jacobson writes:
> I am building a description of page state using a list of pageStyles
> > data PageStyle=    Orientation Orient 
> >                | Margin BoxData
> >                | Border BoxData
> >                | CurrentYPos Float
> >                | CurrentXPos Float
> 
> To extract particular items from the current pagestate, I create functions
> of the form:
> 
> > border [] = error "no border in page"
> > border (a:xs) = case a of
> >     Border x -> x
> >     otherwise -> border xs
> 
> It would be much nicer if I could create a generalized form of this like:
> > border p = extract Border "no border in page" p
> 
> But the extract function appears to be illegal:
> > extract f s [] = error s
> > extract f s (a:xs) = case a of
> >          f x -> x
> >          otherwise -> extract f s xs
> 
> Is there another way of getting this functionality?
> 
> -Alex-
> 
> ___________________________________________________________________
> S. Alexander Jacobson                 i2x Media  
> 1-212-697-0184 voice                  1-212-697-1427 fax


Reply via email to