Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fmap on functions in Haskell

Tags:

haskell

I'm trying to implement fmap for functions and can't quite figure out how to the "lift" applies to a function as compared to how all the documentation refers to simple kinds like Maybe

The type of the function I want to implement is

fmapFunction :: (a -> b) -> (e -> a) -> (e -> b)

Any ideas how I should go about this?

like image 757
Squazic Avatar asked Dec 22 '22 00:12

Squazic


1 Answers

It may be easier to see if you flip the types around:

(e -> a) -> (a -> b) -> (e -> b)

We can turn an e into an a, and an a into a b. So how can we turn an e into a b?

Don't focus too much on "lifting"; with Functor instances, the best way to discover the implementation is simply to follow the type.

like image 94
ehird Avatar answered Jan 21 '23 04:01

ehird