Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion examples/passing/DerivingFunctor.purs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
6 changes: 6 additions & 0 deletions src/Language/PureScript/Sugar/TypeClasses/Deriving.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down