Skip to content

Commit

Permalink
Add moral Functor constraint for to and friends
Browse files Browse the repository at this point in the history
  • Loading branch information
glguy committed Jun 2, 2016
1 parent 623f84c commit 14c35e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
15 changes: 11 additions & 4 deletions src/Control/Lens/Getter.hs
Expand Up @@ -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
Expand Down Expand Up @@ -137,15 +144,15 @@ 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 #-}

-- |
-- @
-- '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 #-}

Expand All @@ -164,15 +171,15 @@ 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 #-}

-- |
-- @
-- '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 #-}

Expand Down
2 changes: 1 addition & 1 deletion src/Control/Lens/Review.hs
Expand Up @@ -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 #-}

Expand Down

0 comments on commit 14c35e0

Please sign in to comment.