Skip to content

Commit

Permalink
Migrate Lens.Micro.ProCompat into Lens.Micro.Pro
Browse files Browse the repository at this point in the history
Fixes #177. See #174 (comment) for rationale.
  • Loading branch information
stevenfontanella committed Feb 5, 2024
1 parent 0817497 commit 3f25838
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 39 deletions.
9 changes: 7 additions & 2 deletions microlens-pro/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 0.1.0.0
# 0.2.0

[#105](https://github.com/stevenfontanella/microlens/issues/105) microlens-pro initial release, with `Prism`s and `Iso`s.
* New major release.
* [#177](https://github.com/stevenfontanella/microlens/issues/177) Moves `Lens.Micro.ProCompat` into `Lens.Micro.Pro`.

# 0.1.0

* [#105](https://github.com/stevenfontanella/microlens/issues/105) microlens-pro initial release, with `Prism`s and `Iso`s.
3 changes: 1 addition & 2 deletions microlens-pro/microlens-pro.cabal
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: microlens-pro
version: 0.1.0
version: 0.2.0
synopsis: Prisms and isomorphisms for microlens
description:
This package provides lens-compatible 'Prism' and 'Iso'. Consequently, it
Expand Down Expand Up @@ -47,7 +47,6 @@ source-repository head

library
exposed-modules: Lens.Micro.Pro
Lens.Micro.ProCompat
Lens.Micro.Pro.TH
Lens.Micro.Pro.Internal
Lens.Micro.Pro.Type
Expand Down
28 changes: 18 additions & 10 deletions microlens-pro/src/Lens/Micro/Pro.hs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ This module is home to lens definitions that require
[profunctors](https://hackage.haskell.org/package/profunctors), most notably
'Iso' and 'Prism'. Depending on 'profunctors' is quite the to bear — one
that includes all dependencies of @microlens-platform@. For this reason,
@microlens-pro@ ships with a compatiblity module "Lens.Micro.ProCompat" which
re-exports the entirety of "Lens.Micro.Platform", but with the profunctor-less
definitions hidden and overridden with profunctor'd definitions from this module.
@microlens-pro@ re-exports the entirety of "Lens.Micro.Platform", but
with the profunctor-less definitions hidden and overridden with profunctor'd
definitions from this module.
-}

{-# LANGUAGE DefaultSignatures #-}
Expand Down Expand Up @@ -66,10 +66,11 @@ module Lens.Micro.Pro
, review
, (#)
, unto

, module Lens.Micro.Platform
)
where
--------------------------------------------------------------------------------
import Lens.Micro (has)
import Lens.Micro.Contra
import Lens.Micro.Pro.Type
import Lens.Micro.Pro.Internal
Expand All @@ -89,6 +90,12 @@ import Data.Profunctor.Unsafe
import GHC.Exts (TYPE)
#endif

-- For re-export hiding conflicting names
import Lens.Micro.Platform hiding
( _Left, _Right, _Just, _Nothing, _Show
, strict, lazy, packed, unpacked, non
)

-- implement instances
import qualified Data.Text as Text
import qualified Data.Text.Lazy as Text.Lazy
Expand Down Expand Up @@ -154,8 +161,8 @@ them share names with the lens-__incompatible__ definitions from
[Lens.Micro](https://hackage.haskell.org/package/microlens-0.4.13.1/docs/Lens-Micro.html#g:5)
and
[Lens.Micro.Platform](https://hackage.haskell.org/package/microlens-platform-0.4.3.4/docs/Lens-Micro-Platform.html).
For convenience, we provide a module "Lens.Micro.ProCompat" which emulates
Lens.Micro.Platform, but uses the lens-compatible isos.
For convenience, we re-export Lens.Micro.Platform, but with non-lens-compatible
isos hidden and replaced with lens-compatbile ones.
-}

Expand Down Expand Up @@ -664,7 +671,7 @@ Just "hello worms"
-}

re :: AReview t b -> Getter b t
re p = to (runIdentity #. unTagged #. p .# Tagged .# Identity)
re p = toInternal (runIdentity #. unTagged #. p .# Tagged .# Identity)

{-# INLINE re #-}

Expand All @@ -675,16 +682,17 @@ re p = to (runIdentity #. unTagged #. p .# Tagged .# Identity)
infixr 8 #
{-# INLINE (#) #-}

-- Not exported
-- TODO: `to` is temporarily defined here. This should be in microlens-contra,
-- or better yet, microlens as Contravariant has been in base since at least ghc
-- 8.6.5. This definition isn't perfect either -- the version from lens is:
--
-- to :: (Profunctor p, Contravariant f) => (s -> a) -> Optic' p f s a

to :: (s -> a) -> Getter s a
to k = dimap k (contramap k)
toInternal :: (s -> a) -> Getter s a
toInternal k = dimap k (contramap k)

{-# INLINE to #-}
{-# INLINE toInternal #-}

{- |
Construct a 'Review' out of a constructor. Consider this more pleasant type
Expand Down
2 changes: 0 additions & 2 deletions microlens-pro/src/Lens/Micro/Pro/TH.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ module Lens.Micro.Pro.TH
)
where

import Lens.Micro
import Lens.Micro.Extras
import Lens.Micro.Pro
import Lens.Micro.TH.Internal
(HasTypeVars(..), typeVars, substTypeVars, newNames, conAppsT, inlinePragma)
Expand Down
23 changes: 0 additions & 23 deletions microlens-pro/src/Lens/Micro/ProCompat.hs

This file was deleted.

0 comments on commit 3f25838

Please sign in to comment.