User Tools

Site Tools


codesnippets:compositionoperator

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 -> Double
    f2 n = fromIntegral n :: Double
     
    f3 :: Char -> Double
    f3 = f2 . f1
     
    f4 :: Char -> Double
    f4 ch = f2 (f1 ch)
    • executes with output:
      97.0
      97.0

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
You could leave a comment if you were logged in.
codesnippets/compositionoperator.txt · Last modified: by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki