Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Name for the function with signature: `(a -> a -> b) -> (a -> b)`

I wonder whether 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

It seems somehow related to fold1 (fold with no base case).

like image 551
freddie-freeloader Avatar asked Jan 02 '23 22:01

freddie-freeloader


1 Answers

As has been mentioned by @4castle in the comments, the function you're looking for is join in Control.Monad. It's type is

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

The simple reader monad is (->) r,so if we set m ~ (->) r, we get

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

or, more concisely,

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

which is what you want.

like image 92
Silvio Mayolo Avatar answered Jan 05 '23 11:01

Silvio Mayolo