You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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?
The text was updated successfully, but these errors were encountered:
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
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
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:
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?
The text was updated successfully, but these errors were encountered: