freddie-freeloader
freddie-freeloader

Reputation: 139

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).

Upvotes: 4

Views: 163

Answers (1)

Silvio Mayolo
Silvio Mayolo

Reputation: 70377

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.

Upvotes: 9

Related Questions