Hello community, here is the log from the commit of package ghc-microlens for openSUSE:Factory checked in at 2016-09-05 21:20:19 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/ghc-microlens (Old) and /work/SRC/openSUSE:Factory/.ghc-microlens.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "ghc-microlens" Changes: -------- --- /work/SRC/openSUSE:Factory/ghc-microlens/ghc-microlens.changes 2016-07-21 08:05:21.000000000 +0200 +++ /work/SRC/openSUSE:Factory/.ghc-microlens.new/ghc-microlens.changes 2016-09-05 21:20:21.000000000 +0200 @@ -1,0 +2,10 @@ +Wed Aug 17 18:26:41 UTC 2016 - psimons@suse.com + +- Update to version 0.4.7.0 revision 0 with cabal2obs. + +------------------------------------------------------------------- +Mon Aug 1 10:41:35 UTC 2016 - psimons@suse.com + +- Update to version 0.4.6.0 revision 0 with cabal2obs. + +------------------------------------------------------------------- Old: ---- microlens-0.4.5.0.tar.gz New: ---- microlens-0.4.7.0.tar.gz ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ ghc-microlens.spec ++++++ --- /var/tmp/diff_new_pack.9d6JJ8/_old 2016-09-05 21:20:22.000000000 +0200 +++ /var/tmp/diff_new_pack.9d6JJ8/_new 2016-09-05 21:20:22.000000000 +0200 @@ -18,11 +18,11 @@ %global pkg_name microlens Name: ghc-%{pkg_name} -Version: 0.4.5.0 +Version: 0.4.7.0 Release: 0 Summary: A tiny lens library with no dependencies. If you're writing an app, you probably want microlens-platform, not this License: BSD-3-Clause -Group: System/Libraries +Group: Development/Languages/Other Url: https://hackage.haskell.org/package/%{pkg_name} Source0: https://hackage.haskell.org/package/%{pkg_name}-%{version}/%{pkg_name}-%{version}.tar.gz BuildRequires: ghc-Cabal-devel @@ -101,15 +101,12 @@ %prep %setup -q -n %{pkg_name}-%{version} - %build %ghc_lib_build - %install %ghc_lib_install - %post devel %ghc_pkg_recache ++++++ microlens-0.4.5.0.tar.gz -> microlens-0.4.7.0.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/microlens-0.4.5.0/CHANGELOG.md new/microlens-0.4.7.0/CHANGELOG.md --- old/microlens-0.4.5.0/CHANGELOG.md 2016-07-02 18:34:58.000000000 +0200 +++ new/microlens-0.4.7.0/CHANGELOG.md 2016-08-12 00:26:02.000000000 +0200 @@ -1,3 +1,12 @@ +# 0.4.7.0 + +* Fixed the [Haddock crash on GHC 8](https://github.com/aelve/microlens/issues/72) by removing default method implementations (`each = traverse` and `ix = ixAt`). If you had custom instances of `Ixed` or `Each` which relied on default methods, they'd stop working. + +# 0.4.6.0 + +* Added `traverseOf` and `traverseOf_`. +* Changed fixities of `#.` and `.#` to the ones in the profunctors package. Those operators are only available from `Lens.Micro.Internal`, so this shouldn't affect most users. + # 0.4.5.0 * Added `<&>` (which makes lens creation easier). diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/microlens-0.4.5.0/microlens.cabal new/microlens-0.4.7.0/microlens.cabal --- old/microlens-0.4.5.0/microlens.cabal 2016-07-02 18:34:58.000000000 +0200 +++ new/microlens-0.4.7.0/microlens.cabal 2016-08-12 00:26:02.000000000 +0200 @@ -1,5 +1,5 @@ name: microlens -version: 0.4.5.0 +version: 0.4.7.0 synopsis: A tiny lens library with no dependencies. If you're writing an app, you probably want microlens-platform, not this. description: NOTE: If you're writing an app, you probably want <http://hackage.haskell.org/package/microlens-platform microlens-platform> – it has the most features. <http://hackage.haskell.org/package/microlens microlens> is intended more for library writers who want a tiny lens library (after all, lenses are pretty useful for everything, not just for updating records!). diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/microlens-0.4.5.0/src/Lens/Micro/Internal.hs new/microlens-0.4.7.0/src/Lens/Micro/Internal.hs --- old/microlens-0.4.5.0/src/Lens/Micro/Internal.hs 2016-07-02 18:34:58.000000000 +0200 +++ new/microlens-0.4.7.0/src/Lens/Micro/Internal.hs 2016-08-12 00:26:02.000000000 +0200 @@ -5,7 +5,6 @@ UndecidableInstances, RankNTypes, ScopedTypeVariables, -DefaultSignatures, KindSignatures, TypeFamilies, MultiParamTypeClasses, @@ -44,6 +43,7 @@ IxValue, Ixed(..), At(..), + ixAt, Field1(..), Field2(..), Field3(..), @@ -152,6 +152,9 @@ ( .# ) pbc _ = unsafeCoerce pbc #endif +infixr 9 #. +infixl 8 .# + ------------------------------------------------------------------------------ -- classes ------------------------------------------------------------------------------ @@ -186,8 +189,6 @@ You can also use 'each' with types from <http://hackage.haskell.org/package/array array>, <http://hackage.haskell.org/package/bytestring bytestring>, and <http://hackage.haskell.org/package/containers containers> by using <http://hackage.haskell.org/package/microlens-ghc microlens-ghc>, or additionally with types from <http://hackage.haskell.org/package/vector vector>, <http://hackage.haskell.org/package/text text>, and <http://hackage.haskell.org/package/unordered-containers unordered-containers> by using <http://hackage.haskell.org/package/microlens-platform microlens-platform>. -} each :: Traversal s t a b - default each :: (Traversable g, s ~ g a, t ~ g b) => Traversal s t a b - each = traverse instance (a~b, q~r) => Each (a,b) (q,r) a q where each f ~(a,b) = (,) <$> f a <*> f b @@ -213,7 +214,9 @@ each = traversed {-# INLINE each #-} -instance Each (Maybe a) (Maybe b) a b +instance Each (Maybe a) (Maybe b) a b where + each = traverse + {-# INLINE each #-} type family Index (s :: *) :: * @@ -260,9 +263,6 @@ You can also use 'ix' with types from <http://hackage.haskell.org/package/array array>, <http://hackage.haskell.org/package/bytestring bytestring>, and <http://hackage.haskell.org/package/containers containers> by using <http://hackage.haskell.org/package/microlens-ghc microlens-ghc>, or additionally with types from <http://hackage.haskell.org/package/vector vector>, <http://hackage.haskell.org/package/text text>, and <http://hackage.haskell.org/package/unordered-containers unordered-containers> by using <http://hackage.haskell.org/package/microlens-platform microlens-platform>. -} ix :: Index m -> Traversal' m (IxValue m) - default ix :: (At m) => Index m -> Traversal' m (IxValue m) - ix = ixAt - {-# INLINE ix #-} class Ixed m => At m where {- | diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/microlens-0.4.5.0/src/Lens/Micro/Type.hs new/microlens-0.4.7.0/src/Lens/Micro/Type.hs --- old/microlens-0.4.5.0/src/Lens/Micro/Type.hs 2016-07-02 18:34:58.000000000 +0200 +++ new/microlens-0.4.7.0/src/Lens/Micro/Type.hs 2016-08-12 00:26:02.000000000 +0200 @@ -108,69 +108,12 @@ type SimpleFold s a = forall r. Monoid r => Getting r s a {- | -Lenses in a nutshell: use ('Lens.Micro.^.') to get, ('Lens.Micro..~') to set, ('Lens.Micro.%~') to modify. ('.') composes lenses (i.e. if a @B@ is a part of @A@, and a @C@ is a part of in @B@, then @b.c@ lets you operate on @C@ inside @A@). You can create lenses with 'Lens.Micro.lens', or you can write them by hand (see below). - @Lens s t a b@ is the lowest common denominator of a setter and a getter, something that has the power of both; it has a 'Functor' constraint, and since both 'Const' and 'Identity' are functors, it can be used whenever a getter or a setter is needed. * @a@ is the type of the value inside of structure * @b@ is the type of the replaced value * @s@ is the type of the whole structure * @t@ is the type of the structure after replacing @a@ in it with @b@ - -A 'Lens' can only point at a single value inside a structure (unlike a 'Traversal'). - -It is easy to write lenses manually. The generic template is: - -@ -somelens :: Lens s t a b - --- “f” is the “a -> f b” function, “s” is the structure. -somelens f s = - let - a = ... -- Extract the value from “s”. - rebuildWith b = ... -- Write a function which would - -- combine “s” and modified value - -- to produce new structure. - in - rebuildWith '<$>' f a -- Apply the structure-producing - -- function to the modified value. -@ - -Here's the 'Lens.Micro._1' lens: - -@ -'Lens.Micro._1' :: 'Lens' (a, x) (b, x) a b -'Lens.Micro._1' f (a, x) = (\\b -> (b, x)) '<$>' f a -@ - -Here's a more complicated lens, which extracts /several/ values from a structure (in a tuple): - -@ -type Age = Int -type City = String -type Country = String - -data Person = Person Age City Country - --- This lens lets you access all location-related information about a person. -location :: 'Lens'' Person (City, Country) -location f (Person age city country) = - (\\(city', country') -> Person age city' country') '<$>' f (city, country) -@ - -You even can choose to use a lens to present /all/ information contained in the structure (in a different way). Such lenses are called @<http://hackage.haskell.org/package/lens/docs/Control-Lens-Iso.html#t:Iso Iso>@ in lens's terminology. For instance (assuming you don't mind functions that can error out), here's a lens which lets you act on the string representation of a value: - -@ -string :: (Read a, Show a) => 'Lens'' a String -string f s = read '<$>' f (show s) -@ - -Using it to reverse a number: - -@ ->>> 123 'Lens.Micro.&' string 'Lens.Micro.%~' reverse -321 -@ -} type Lens s t a b = forall f. Functor f => (a -> f b) -> s -> f t @@ -180,20 +123,8 @@ type Lens' s a = Lens s s a a {- | -Traversals in a nutshell: they're like lenses but they can point at multiple values. Use ('Lens.Micro.^..') to get all values, ('Lens.Micro.^?') to get the 1st value, ('Lens.Micro..~') to set values, ('Lens.Micro.%~') to modify them. ('.') composes traversals just as it composes lenses. ('Lens.Micro.^.') can be used with traversals as well, but don't confuse it with ('Lens.Micro.^..'). - @Traversal s t a b@ is a generalisation of 'Lens' which allows many targets (possibly 0). It's achieved by changing the constraint to 'Applicative' instead of 'Functor' – indeed, the point of 'Applicative' is that you can combine effects, which is just what we need to have many targets. -Traversals don't differ from lenses when it comes to setting – you can use usual ('Lens.Micro.%~') and ('Lens.Micro..~') to modify and set values. Getting is a bit different, because you have to decide what to do in the case of multiple values. In particular, you can use these combinators (as well as everything else in the “Folds” section): - - * ('Lens.Micro.^..') gets a list of values - * ('Lens.Micro.^?') gets the 1st value (or 'Nothing' if there are no values) - * ('Lens.Micro.^?!') gets the 1st value and throws an exception if there are no values - -In addition, ('Lens.Micro.^.') works for traversals as well – it combines traversed values using the ('Data.Monoid.<>') operation (if the values are instances of 'Monoid'). - -Traversing any value twice is a violation of traversal laws. You can, however, traverse values in any order. - Ultimately, traversals should follow 2 laws: @ @@ -202,6 +133,8 @@ @ The 1st law states that you can't change the shape of the structure or do anything funny with elements (traverse elements which aren't in the structure, create new elements out of thin air, etc.). The 2nd law states that you should be able to fuse 2 identical traversals into one. For a more detailed explanation of the laws, see <http://artyom.me/lens-over-tea-2#traversal-laws this blog post> (if you prefer rambling blog posts), or <https://www.cs.ox.ac.uk/jeremy.gibbons/publications/iterator.pdf The Essence Of The Iterator Pattern> (if you prefer papers). + +Traversing any value twice is a violation of traversal laws. You can, however, traverse values in any order. -} type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/microlens-0.4.5.0/src/Lens/Micro.hs new/microlens-0.4.7.0/src/Lens/Micro.hs --- old/microlens-0.4.5.0/src/Lens/Micro.hs 2016-07-02 18:34:58.000000000 +0200 +++ new/microlens-0.4.7.0/src/Lens/Micro.hs 2016-08-12 00:26:02.000000000 +0200 @@ -57,11 +57,13 @@ (^..), toListOf, (^?), (^?!), + traverseOf_, has, folded, folding, -- * Lens: a combined getter-and-setter + -- $lenses-note Lens, Lens', lens, at, @@ -73,7 +75,9 @@ non, -- * Traversal: a lens iterating over several elements + -- $traversals-note Traversal, Traversal', + traverseOf, singular, failing, filtered, @@ -588,6 +592,21 @@ infixl 8 ^?! {- | +Apply an action to all targets and discard the result (like 'Control.Monad.mapM_' or 'Data.Foldable.traverse_'): + +>>> traverseOf_ both putStrLn ("hello", "world") +hello +world + +Works with anything that allows getting, including lenses and getters (so, anything except for 'ASetter'). Should be faster than 'traverseOf' when you don't need the result. +-} +traverseOf_ + :: Functor f + => Getting (Traversed r f) s a -> (a -> f r) -> s -> f () +traverseOf_ l f = void . getTraversed #. foldMapOf l (Traversed #. f) +{-# INLINE traverseOf_ #-} + +{- | 'has' checks whether a getter (any getter, including lenses, traversals, and folds) returns at least 1 value. Checking whether a list is non-empty: @@ -616,6 +635,97 @@ -- Lenses ------------------------------------------------------------------ +{- $lenses-note + +Lenses are composable “pointers” at values inside some bigger structure (e.g. '_1' points at the first element of a tuple). You can use ('^.') to get, ('.~') to set, and ('%~') to modify: + +>>> (1,2) ^. _1 +1 +>>> (1,2) & _1 .~ 3 +(3,2) +>>> (1,2) & _1 %~ negate +(-1,2) + +To apply a monadic action (or an 'Applicative' action, or even a 'Functor' action) to the pointed value, just apply the lens directly or use 'traverseOf' (or 'traverseOf_' if you don't need the result): + +>>> traverseOf_ _1 print (1,2) +1 + +>>> _1 id (Just 1, 2) +Just (1, 2) +>>> _1 id (Nothing, 2) +Nothing + +A 'Lens' can only point at a single value inside a structure (unlike a 'Traversal'). + +('.') composes lenses (i.e. if a @B@ is a part of @A@, and a @C@ is a part of @B@, then @b.c@ lets you operate on @C@ inside @A@). You can create lenses with 'lens', or you can write them by hand. + +There are several ways to get lenses for some datatype: + +* They can already be provided by the package, by @microlens@, or by some other package like <http://hackage.haskell.org/package/microlens-platform microlens-platform>. + +* They can be provided by some unofficial package (like <http://hackage.haskell.org/package/microlens-aeson microlens-aeson>). + +* You can get them by combining already existing lenses. + +* You can derive them with Template Haskell (with <http://hackage.haskell.org/package/microlens-th microlens-th>). + +* You can write them with 'lens' if you have a setter and a getter. It's a simple and good way. + +* You can write them manually (sometimes it looks a bit better than the variant with 'lens', sometimes worse). The generic template is as follows: + +@ +somelens :: Lens s t a b + +-- “f” is the “a -> f b” function, “s” is the structure. +somelens f s = + let + a = ... -- Extract the value from “s”. + rebuildWith b = ... -- Write a function which would + -- combine “s” and modified value + -- to produce new structure. + in + rebuildWith '<$>' f a -- Apply the structure-producing + -- function to the modified value. +@ + +Here's the '_1' lens, for instance: + +@ +'_1' :: 'Lens' (a, x) (b, x) a b +'_1' f (a, x) = (\\b -> (b, x)) '<$>' f a +@ + +Here's a more complicated lens, which extracts /several/ values from a structure (in a tuple): + +@ +type Age = Int +type City = String +type Country = String + +data Person = Person Age City Country + +-- This lens lets you access all location-related information about a person. +location :: 'Lens'' Person (City, Country) +location f (Person age city country) = + (\\(city', country') -> Person age city' country') '<$>' f (city, country) +@ + +You even can choose to use a lens to present /all/ information contained in the structure (in a different way). Such lenses are called @<http://hackage.haskell.org/package/lens/docs/Control-Lens-Iso.html#t:Iso Iso>@ in lens's terminology. For instance (assuming you don't mind functions that can error out), here's a lens which lets you act on the string representation of a value: + +@ +string :: (Read a, Show a) => 'Lens'' a String +string f s = read '<$>' f (show s) +@ + +Using it to reverse a number: + +@ +>>> 123 '&' string '%~' reverse +321 +@ +-} + {- | 'lens' creates a 'Lens' from a getter and a setter. The resulting lens isn't the most effective one (because of having to traverse the structure twice when modifying), but it shouldn't matter much. @@ -734,6 +844,43 @@ -- Traversals -------------------------------------------------------------- +{- $traversals-note + +Traversals are like lenses but they can point at multiple values. Use ('^..') to get all values, ('^?') to get the 1st value, ('.~') to set values, ('%~') to modify them. ('.') composes traversals just as it composes lenses. ('^.') can be used with traversals as well, but don't confuse it with ('^..') – ('^..') gets all traversed values, ('^.') combines traversed values using the ('Data.Monoid.<>') operation (if the values are instances of 'Monoid'; if they aren't, it won't compile). 'traverseOf' and 'traverseOf_' apply an action to all pointed values of a traversal. + +Traversals don't differ from lenses when it comes to setting – you can use usual ('%~') and ('.~') to modify and set values. Getting is a bit different, because you have to decide what to do in the case of multiple values. In particular, you can use these combinators (as well as everything else in the “Folds” section): + + * ('^..') gets a list of values + * ('^?') gets the 1st value (or 'Nothing' if there are no values) + * ('^?!') gets the 1st value and throws an exception if there are no values + +If you are sure that the traversal will traverse at least one value, you can convert it to a lens with 'singular'. + +'traversed' is a universal traversal for anything that belongs to the 'Traversable' typeclass. However, in many cases 'each' works as well and is shorter and nicer-looking. +-} + +{- | +Apply an action to all targets (like 'Control.Monad.mapM' or 'Data.Traversable.traverse'): + +>>> traverseOf both readFile ("file1", "file2") +(<contents of file1>, <contents of file2>) + +>>> traverseOf _1 id (Just 1, 2) +Just (1, 2) +>>> traverseOf _1 id (Nothing, 2) +Nothing + +You can also just apply the lens\/traversal directly (but 'traverseOf' might be more readable): + +>>> both readFile ("file1", "file2") +(<contents of file1>, <contents of file2>) + +If you don't need the result, use 'traverseOf_'. +-} +traverseOf :: LensLike f s t a b -> (a -> f b) -> s -> f t +traverseOf = id +{-# INLINE traverseOf #-} + {- | 'singular' turns a traversal into a lens that behaves like a single-element traversal: @@ -1091,6 +1238,14 @@ -- Some of the guts of lens +newtype Traversed a f = Traversed { getTraversed :: f a } + +instance Applicative f => Monoid (Traversed a f) where + mempty = Traversed (pure (error "Lens.Micro.Traversed: value used")) + {-# INLINE mempty #-} + Traversed ma `mappend` Traversed mb = Traversed (ma *> mb) + {-# INLINE mappend #-} + newtype Bazaar a b t = Bazaar (forall f. Applicative f => (a -> f b) -> f t) instance Functor (Bazaar a b) where