Show
Ignore:
Timestamp:
10/01/06 04:46:04 (2 years ago)
Author:
audreyt
Message:

* Pugs.Prim.List: Make max/min not compare the first element twice.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Prim/List.hs

    r13728 r13763  
    6464 
    6565op1Min :: Val -> Eval Val 
    66 op1Min v = op1MinMax (== False) v 
     66op1Min v = op1MinMax not v 
    6767 
    6868op1Max :: Val -> Eval Val 
    69 op1Max v = op1MinMax (== True) v 
     69op1Max v = op1MinMax id v 
    7070 
    7171-- min_or_max is a function which negates truth/falsehood. 
     
    9191    op1MinMax' _ _ [] = return undef 
    9292    -- We have to supply our own comparator... 
    93     op1MinMax' _ Nothing valList = foldM default_compare (head valList) valList 
     93    op1MinMax' _ Nothing valList = foldM default_compare (head valList) (tail valList) 
    9494    -- or use the one of the user 
    9595    op1MinMax' min_or_max (Just subVal) valList = do 
     
    106106              --   +1 ==> a > b 
    107107              -- We call min_or_max so we can work for both min() and max(). 
    108               return $ if min_or_max (int > (0::VInt)) then a else b) (head valList) valList 
     108              return $ if min_or_max (int > (0::VInt)) then a else b) (head valList) (tail valList) 
    109109    -- This is the default comparision function, which will be used if the user 
    110110    -- hasn't specified a own comparision function.