applyEach :: [ a -> b ] -> a -> [b]
applyEach fs x = zipWith id fs (repeat x)
applyEach' :: [ a -> b ] -> a -> [b]
applyEach' fs = (zipWith id fs) . repeat -- eta reduction
applyEach'' :: [ a -> b ] -> a -> [b]
applyEach'' fs x = [ f x | f <- fs ]
applyEach''' :: [ a -> b ] -> a -> [b]
applyEach''' [] _ = []
applyEach''' (f:fs) x = f x : applyEach''' fs x
----- test -----
main = do
putStrLn $ show $ applyEach [simple 2 2, (+3)] 5
putStrLn $ show $ applyEach' [simple 2 2, (+3)] 5
putStrLn $ show $ applyEach'' [simple 2 2, (+3)] 5
putStrLn $ show $ applyEach''' [simple 2 2, (+3)] 5
{-
applyEach :: [ a -> b ] -> a -> [b]
applyEach fs x = zipWith g fs (repeat x)
g :: (a -> b) -> a -> b
g f x = f x
<=> g f = f -- after eta reduction
<=> g = ? -- after eta reduction
g = id -- id :: a -> a
g (f x) = (f x)
-}
simple :: Int -> Int -> Int -> Int
simple x y z = x * (y+z)
This entry was posted
on Tuesday, June 5th, 2007 at 5:05 pm and is filed under Haskell - SOE.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.