
26 Feb
2006
26 Feb
'06
8 a.m.
Your solution works, but is slightly wasteful with (repair) traversing the whole list again. Here is a slightly more efficient expression: -- Precondition: The first parameter (xs) is sorted (ascending) : -- assert (all (zipWith (<=) (xs, tail xs))) -- low' < high' -- low < high normInterval :: [Double] -> Double -> Double -> [Double] normInterval xs low high = let low' = head xs; high' = last xs; scale = (high-low)/(high'-low') middle = init (tail xs) in (low : [scale*(x-low')+low) | x <-middle])++[high] -- Chris