Created
April 18, 2016 08:29
-
-
Save Jim-Holmstroem/7e8614b0472277ea1816bccd877ee3af to your computer and use it in GitHub Desktop.
First try (not working): Functor over Functor as Functor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Prelude> data TwoD f g a = TwoD (f (g a)) deriving Show | |
Prelude> TwoD [Just 3] | |
TwoD [Just 3] | |
Prelude> :t TwoD [Just 3] | |
TwoD [Just 1] :: Num a => TwoD [] Maybe a | |
Prelude> :{ | |
Prelude| instance (Functor f, Functor g) => Functor (TwoD f g) where | |
Prelude| fmap o = fmap (fmap o) | |
Prelude| :} | |
<interactive>:20:18: | |
Couldn't match type ‘a’ with ‘f0 a’ | |
‘a’ is a rigid type variable bound by | |
the type signature for fmap :: (a -> b) -> TwoD f g a -> TwoD f g b | |
at <interactive>:20:3 | |
Expected type: a -> b | |
Actual type: f0 a -> f0 b | |
Relevant bindings include | |
o :: a -> b (bound at <interactive>:20:8) | |
fmap :: (a -> b) -> TwoD f g a -> TwoD f g b | |
(bound at <interactive>:20:3) | |
In the first argument of ‘fmap’, namely ‘(fmap o)’ | |
In the expression: fmap (fmap o) | |
<interactive>:20:18: | |
Couldn't match type ‘b’ with ‘f0 b’ | |
‘b’ is a rigid type variable bound by | |
the type signature for fmap :: (a -> b) -> TwoD f g a -> TwoD f g b | |
at <interactive>:20:3 | |
Expected type: a -> b | |
Actual type: f0 a -> f0 b | |
Relevant bindings include | |
o :: a -> b (bound at <interactive>:20:8) | |
fmap :: (a -> b) -> TwoD f g a -> TwoD f g b | |
(bound at <interactive>:20:3) | |
In the first argument of ‘fmap’, namely ‘(fmap o)’ | |
In the expression: fmap (fmap o) |
There is also -XDeriveFunctor
which does this by deriving (Functor)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had just forgot the unpacking of TwoD