.>" Combines functions together, opposite the direction ".". But wh...">

Haskell>.> Designation

In the book "Creating Function Programming" the symbol ">.>" Combines functions together, opposite the direction ".". But when I implemented it using ghci, it displays the error ">.>" From scope. What for? Is this an old notation that is no longer in use?

+4
source share
3 answers

This is probably just a function defined in the book (I have not read the book). AFAIK, >.> Is not used anywhere. You can define it yourself:

 (>.>) = flip (.) 

This actually means (#) .

Since the functions arrows "Control.Category" , you can also use >>> , for example

 Prelude Control.Category> ((*2) . (+1)) 4 10 Prelude Control.Category> ((*2) <<< (+1)) 4 10 Prelude Control.Category> ((*2) >>> (+1)) 4 9 Prelude Control.Category> ((+1) >>> (*2)) 4 10 
+6
source

>.> not defined by default, but you can define it yourself:

 infixl 9 >.> (>.>) = flip (.) 

or equivalently

 infixl 9 >.> f >.> g = g . f 

(I gave a commit declaration based on infixr 9 . In Prelude .)

+7
source

(>.>) does not appear to be defined in standard libraries. However, there is (>>>) in Control.Category , which behaves the same:

 Prelude> :m + Control.Category Prelude Control.Category> :i (>>>) (>>>) :: Category cat => cat ab -> cat bc -> cat ac -- Defined in Control.Category infixr 1 >>> Prelude Control.Category> let f = (* 2) >>> (+ 3) Prelude Control.Category> f 5 13 

Please note that you can use Hoogle to figure this out.

In addition, you can, of course, always define such an operator yourself:

 (>.>) :: (a -> b) -> (b -> c) -> (a -> c) f >.> g = g . f 

Then you can write:

 Main*> ((* 2) >.> (+ 3)) 5 13 
+3
source

Source: https://habr.com/ru/post/1388274/


All Articles