Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Chapter 4] Is it possible to have an instance of Functor for "Trap e" of "Secret e a"? #576

Open
IceAsteroid opened this issue Jun 18, 2024 · 0 comments

Comments

@IceAsteroid
Copy link

IceAsteroid commented Jun 18, 2024

Hi, guys, greetings!

This is a very confusing part of typeclass to me.

I can define an instance for "Secret e a", which the "Trap e" is being fixed.

But I can't figure out the way to also define a Functor instance for the first type variable, which is the value "Trap e" of "Secret e a"

For example:

data Secret e a
    = Trap e
    | Reward a
    deriving (Show, Eq)

-- This one for the value "Reward a" works.
-- instance Functor (Secret e) where
--   fmap :: (a -> b) -> Secret e a -> Secret e b
--   fmap _ (Trap a) = Trap a
--   fmap f (Reward a) = Reward (f a)

But how do I possibly have the value "Trap e" also to work for fmap, is it for some reason that such cases are not necessary?

@IceAsteroid IceAsteroid changed the title Is it possible to have an instance of Functor for "Trap e" of "Secret e a"? [Chapter 3] Is it possible to have an instance of Functor for "Trap e" of "Secret e a"? Jun 18, 2024
@IceAsteroid IceAsteroid changed the title [Chapter 3] Is it possible to have an instance of Functor for "Trap e" of "Secret e a"? [Chapter 4] Is it possible to have an instance of Functor for "Trap e" of "Secret e a"? Jun 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant