diff --git a/examples/passing/DerivingFunctor.purs b/examples/passing/DerivingFunctor.purs index 765564bb91..18c4deed90 100644 --- a/examples/passing/DerivingFunctor.purs +++ b/examples/passing/DerivingFunctor.purs @@ -15,9 +15,11 @@ data M f a | M4 (MyRecord a) derive instance eqM :: (Eq1 f, Eq a) => Eq (M f a) - derive instance functorM :: Functor f => Functor (M f) +data T a = T (forall t. Show t => t -> a) +derive instance functorT :: Functor T + type MA = M Array main = do @@ -26,4 +28,9 @@ main = do assert $ map show (M2 [0, 1] :: MA Int) == M2 ["0", "1"] assert $ map show (M3 {foo: 0, bar: 1, baz: [2, 3]} :: MA Int) == M3 {foo: 0, bar: "1", baz: ["2", "3"]} assert $ map show (M4 { myField: 42 }) == M4 { myField: "42" } :: MA String + + case map show (T \_ -> 42) of + T f -> assert $ f "hello" == "42" + _ -> assert false + log "Done" diff --git a/src/Language/PureScript/Sugar/TypeClasses/Deriving.hs b/src/Language/PureScript/Sugar/TypeClasses/Deriving.hs index 1d8100f1fe..678e6274ed 100755 --- a/src/Language/PureScript/Sugar/TypeClasses/Deriving.hs +++ b/src/Language/PureScript/Sugar/TypeClasses/Deriving.hs @@ -742,6 +742,12 @@ deriveFunctor ss mn syns ds tyConNm = do mkAssignment ((Label l), x) = (l, App x (Accessor l argVar)) return (lam ss arg (ObjectUpdate argVar (mkAssignment <$> updates))) + -- quantifiers + goType (ForAll scopedVar t _) | scopedVar /= iTyName = goType t + + -- constraints + goType (ConstrainedType _ t) = goType t + -- under a `* -> *`, just assume functor for now goType (TypeApp _ t) = fmap (App mapVar) <$> goType t