praxis

Various programming exercises.
git clone git://git.jtobin.io/praxis.git
Log | Files | Refs

ForwardDifference.hs (311B)


      1 
      2 module ForwardDifference where
      3 
      4 leastForwardDifference :: (Ord a, Num a) => [a] -> Maybe a
      5 leastForwardDifference xs = safeMaximum diffs where
      6   diffs = zipWith (-) xs mins
      7   mins  = scanl1 min xs
      8 
      9 safeMaximum :: Ord a => [a] -> Maybe a
     10 safeMaximum []     = Nothing
     11 safeMaximum (x:xs) = Just $ foldr max x xs
     12