4

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?

ehird
40.9k3 gold badges184 silver badges184 bronze badges
asked Mar 28, 2012 at 23:51
1
  • 4
    You could also cheat. Commented Mar 29, 2012 at 4:12

1 Answer 1

11

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.

answered Mar 29, 2012 at 0:04
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.