import Prelude hiding (flip) -- Compute the derivation of a (continuous) function. derive :: (Float -> Float) -> (Float -> Float) derive f = f' where f' x = (f (x + dx) - f x) / dx dx :: Float dx = 0.001 square :: Float -> Float square x = x * x cubic :: Float -> Float cubic x = x * x * x -- with lambda abstraction deriveL :: (Float -> Float) -> (Float -> Float) deriveL f = \x -> (f (x + dx) - f x) / dx -- Addition of two floats: add :: Float -> Float -> Float add x y = x + y add0 :: Float -> Float -> Float add0 = \x y -> x + y add1 :: Float -> (Float -> Float) add1 x = \y -> x + y takeFive :: [a] -> [a] takeFive = take 5 inc :: Int -> Int --inc = (+) 1 --inc = (1 +) inc = (+ 1) takeABC :: Int -> String takeABC = (flip take) "abcdefghijkl" -- Flips the order of the two arguments flip :: (a -> b -> c) -> (b -> a -> c) flip f = \y x -> f x y