Anonymous user
First-class functions: Difference between revisions
→{{header|Haskell}}: Added type annotations on functions
(→{{header|Haskell}}: Added type annotations on functions) |
|||
Line 1,240:
=={{header|Haskell}}==
<lang haskell>
Prelude> let compose f g = \x -> f (g x) -- this is already implemented in Haskell as the "." operator▼
croot :: Floating a => a -> a
croot x = x ** (1/3)
Prelude> let funclist = [sin, cos, cube]▼
Prelude> let funclisti = [asin, acos, croot]▼
▲
-- compose :: (a -> b) -> (b -> c) -> a -> c
[0.5,0.4999999999999999,0.5]</lang>▼
-- compose f g = \x -> g (f x)
funclist :: Floating a => [a -> a]
invlist :: Floating a => [a -> a]
main :: IO ()
main = print $ zipWith (\f i -> f . i $ 0.5) funclist invlist </lang>
{{output}}
=={{header|Icon}} and {{header|Unicon}}==
|