codesnippets:compositionoperator
This is an old revision of the document!
Composition operator
- composition operator is “.”
- type:
(b → c) → (a → b) → a → c - takes two functions as parameter and combines the functions
- first function is applied to the result of the second function
- example:
import qualified Data.Char as Ch (ord) main :: IO () main = do print $ f3 'a' print $ f4 'a' f1 :: Char -> Integer f1 ch = toInteger $ Ch.ord(ch) f2 :: Integer -> (Integer, Double) f2 n = (n, fromIntegral n :: Double) f3 :: Char -> (Integer, Double) f3 = f2 . f1 f4 :: Char -> (Integer, Double) f4 ch = f2 (f1 ch)
- executes with output:
(97,97.0) (97,97.0)
You could leave a comment if you were logged in.
codesnippets/compositionoperator.1617807334.txt.gz · Last modified: (external edit)
