From 14c35e022591a88c5142a9c63dd99419070479f0 Mon Sep 17 00:00:00 2001 From: Eric Mertens Date: Thu, 2 Jun 2016 09:47:37 -0700 Subject: [PATCH] Add moral Functor constraint for to and friends --- src/Control/Lens/Getter.hs | 15 +++++++++++---- src/Control/Lens/Review.hs | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Control/Lens/Getter.hs b/src/Control/Lens/Getter.hs index 0be4c4b6e..936e2e57a 100644 --- a/src/Control/Lens/Getter.hs +++ b/src/Control/Lens/Getter.hs @@ -16,6 +16,13 @@ {-# LANGUAGE NoPolyKinds #-} {-# LANGUAGE NoDataKinds #-} #endif + +-- Disable the warnings generated by 'to', 'ito', 'like', 'ilike'. +-- These functions are intended to produce 'Getters'. Without this constraint +-- users would get warnings when annotating types at uses of these functions. +#if __GLASGOW_HASKELL__ >= 711 +{-# OPTIONS_GHC -fno-warn-redundant-constraints #-} +#endif ------------------------------------------------------------------------------- -- | -- Module : Control.Lens.Getter @@ -137,7 +144,7 @@ infixl 8 ^., ^@. -- @ -- 'to' :: (s -> a) -> 'IndexPreservingGetter' s a -- @ -to :: (Profunctor p, Contravariant f) => (s -> a) -> Optic' p f s a +to :: (Profunctor p, Contravariant f, Functor f) => (s -> a) -> Optic' p f s a to k = dimap k (contramap k) {-# INLINE to #-} @@ -145,7 +152,7 @@ to k = dimap k (contramap k) -- @ -- 'ito' :: (s -> (i, a)) -> 'IndexedGetter' i s a -- @ -ito :: (Indexable i p, Contravariant f) => (s -> (i, a)) -> Over' p f s a +ito :: (Indexable i p, Contravariant f, Functor f) => (s -> (i, a)) -> Over' p f s a ito k = dimap k (contramap (snd . k)) . uncurry . indexed {-# INLINE ito #-} @@ -164,7 +171,7 @@ ito k = dimap k (contramap (snd . k)) . uncurry . indexed -- @ -- 'like' :: a -> 'IndexPreservingGetter' s a -- @ -like :: (Profunctor p, Contravariant f) => a -> Optic' p f s a +like :: (Profunctor p, Contravariant f, Functor f) => a -> Optic' p f s a like a = to (const a) {-# INLINE like #-} @@ -172,7 +179,7 @@ like a = to (const a) -- @ -- 'ilike' :: i -> a -> 'IndexedGetter' i s a -- @ -ilike :: (Indexable i p, Contravariant f) => i -> a -> Over' p f s a +ilike :: (Indexable i p, Contravariant f, Functor f) => i -> a -> Over' p f s a ilike i a = ito (const (i, a)) {-# INLINE ilike #-} diff --git a/src/Control/Lens/Review.hs b/src/Control/Lens/Review.hs index 62abb7d38..c2ac8d76c 100644 --- a/src/Control/Lens/Review.hs +++ b/src/Control/Lens/Review.hs @@ -108,7 +108,7 @@ un = unto . view -- 're' :: 'Prism' s t a b -> 'Getter' b t -- 're' :: 'Iso' s t a b -> 'Getter' b t -- @ -re :: Contravariant f => AReview t b -> LensLike' f b t +re :: AReview t b -> Getter b t re p = to (runIdentity #. unTagged #. p .# Tagged .# Identity) {-# INLINE re #-}