Name for function with signature: `(a & # 8594; a & # 8594; b) & # 8594; (a & # 8594; b) `

I wonder if there is a good name for functions with the following signature and implementation (Haskell notation):

humble :: (a -> a -> b) -> a -> b
humble f x = f x x

Something seems to be related to fold1( foldwithout the base case).

+4
source share
1 answer

As mentioned in the comments of @ 4castle, the feature you are looking for is joinin Control.Monad. This type

join :: Monad m => m (m a) -> m a

The reader’s simple monad (->) r, so if we install m ~ (->) r, we get

join :: (->) r ((->) r a) -> (->) r a

or, more briefly,

join :: (r -> r -> a) -> (r -> a)

What would you like.

+8
source

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


All Articles