microlens-platform (empty) → 0.1.0.0
raw patch · 5 files changed
+347/−0 lines, 5 filesdep +basedep +hashabledep +microlenssetup-changed
Dependencies added: base, hashable, microlens, microlens-ghc, microlens-mtl, microlens-th, text, unordered-containers, vector
Files
- CHANGELOG.md +3/−0
- LICENSE +30/−0
- Setup.hs +2/−0
- microlens-platform.cabal +44/−0
- src/Lens/Micro/Platform.hs +268/−0
+ CHANGELOG.md view
@@ -0,0 +1,3 @@+# 0.1.0.0++Initial release.
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright (c) 2015, Artyom++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Artyom nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ microlens-platform.cabal view
@@ -0,0 +1,44 @@+name: microlens-platform+version: 0.1.0.0+synopsis: Feature-complete microlens+description:+ This package exports a module which is the recommended starting point for using <http://hackage.haskell.org/package/microlens microlens> if you aren't trying to keep your dependencies minimal. By importing @Lens.Micro.Platform@ you get all functions and instances from <http://hackage.haskell.org/package/microlens microlens>, <http://hackage.haskell.org/package/microlens-mtl microlens-mtl>, <http://hackage.haskell.org/package/microlens-ghc microlens-ghc>, as well as instances for @Vector@, @Text@, and @HashMap@.+ .+ This package is a part of the <http://hackage.haskell.org/package/microlens microlens> family; see the readme <https://github.com/aelve/microlens#readme on Github>.+license: BSD3+license-file: LICENSE+author: Artyom+maintainer: Artyom <yom@artyom.me>+homepage: http://github.com/aelve/microlens+bug-reports: http://github.com/aelve/microlens/issues+category: Data, Lenses+build-type: Simple+extra-source-files:+ CHANGELOG.md+cabal-version: >=1.10++source-repository head+ type: git+ location: git://github.com/aelve/microlens.git++library+ exposed-modules: Lens.Micro.Platform+ -- other-modules: + -- other-extensions: + build-depends: base >=4.5 && <5+ , hashable >=1.1.2.3 && <1.3+ , microlens ==0.3.0.*+ , microlens-ghc ==0.2.0.*+ , microlens-mtl ==0.1.4.*+ , microlens-th ==0.2.1.*+ , text >=0.11 && <1.3+ , unordered-containers >=0.2.4 && <0.3+ , vector >=0.9 && <0.12++ ghc-options:+ -Wall -fwarn-tabs+ -O2 -fdicts-cheap -funbox-strict-fields+ -fmax-simplifier-iterations=10++ hs-source-dirs: src+ default-language: Haskell2010
+ src/Lens/Micro/Platform.hs view
@@ -0,0 +1,268 @@+{-# LANGUAGE+CPP,+TypeFamilies,+MultiParamTypeClasses,+FlexibleInstances,+UndecidableInstances+ #-}++-- without -fno-warn-dodgy-exports it complains about Lens.Micro.GHC+-- exporting nothing (and I want the export to be seen in the Haddocks)+{-# OPTIONS_GHC -fno-warn-orphans -fno-warn-dodgy-exports #-}++#ifndef MIN_VERSION_base+#define MIN_VERSION_base(x,y,z) 1+#endif+++{- |+This module is an approximation for @<http://hackage.haskell.org/package/lens/docs/Control-Lens.html Control.Lens>@ from <http://hackage.haskell.org/package/lens lens>; by importing it you get all functions and instances from <http://hackage.haskell.org/package/microlens microlens>, <http://hackage.haskell.org/package/microlens-mtl microlens-mtl>, <http://hackage.haskell.org/package/microlens-ghc microlens-ghc>, as well as the following instances:++* 'at' for 'HashMap'++* 'each' and 'ix' for++ * 'HashMap'+ * 'Vector.Vector' and variants (unboxed vectors, etc)+ * strict 'T.Text' and lazy 'TL.Text'++* '_head', '_tail', '_init', '_last' for++ * 'Vector.Vector' and variants+ * strict and lazy @Text@+-}+module Lens.Micro.Platform+(+ module Lens.Micro,+ module Lens.Micro.Mtl,+ module Lens.Micro.TH,+ module Lens.Micro.GHC,+)+where+++import Lens.Micro+import Lens.Micro.Internal+import Lens.Micro.Mtl+import Lens.Micro.TH+import Lens.Micro.GHC ()++import Data.Hashable+import Data.Int+import Data.Monoid++import Data.HashMap.Lazy as HashMap+import Data.Vector as Vector+import Data.Vector.Primitive as Prim+import Data.Vector.Storable as Storable+import Data.Vector.Unboxed as Unboxed+import Data.Vector.Generic as Generic++import qualified Data.Text as T+import qualified Data.Text.Lazy as TL++#if !MIN_VERSION_base(4,8,0)+import Control.Applicative+#endif+++(<&>) :: Functor f => f a -> (a -> b) -> f b+as <&> f = f <$> as+{-# INLINE (<&>) #-}++infixl 1 <&>+++type instance Index (HashMap k a) = k+type instance IxValue (HashMap k a) = a+type instance Index (Vector.Vector a) = Int+type instance IxValue (Vector.Vector a) = a+type instance Index (Prim.Vector a) = Int+type instance IxValue (Prim.Vector a) = a+type instance Index (Storable.Vector a) = Int+type instance IxValue (Storable.Vector a) = a+type instance Index (Unboxed.Vector a) = Int+type instance IxValue (Unboxed.Vector a) = a+type instance Index T.Text = Int+type instance IxValue T.Text = Char+type instance Index TL.Text = Int64+type instance IxValue TL.Text = Char++instance (Eq k, Hashable k) => Ixed (HashMap k a) where+ ix k f m = case HashMap.lookup k m of+ Just v -> f v <&> \v' -> HashMap.insert k v' m+ Nothing -> pure m+ {-# INLINE ix #-}++instance Ixed (Vector.Vector a) where+ ix i f v+ | 0 <= i && i < Vector.length v = f (v Vector.! i) <&> \a -> v Vector.// [(i, a)]+ | otherwise = pure v+ {-# INLINE ix #-}++instance Prim a => Ixed (Prim.Vector a) where+ ix i f v+ | 0 <= i && i < Prim.length v = f (v Prim.! i) <&> \a -> v Prim.// [(i, a)]+ | otherwise = pure v+ {-# INLINE ix #-}++instance Storable a => Ixed (Storable.Vector a) where+ ix i f v+ | 0 <= i && i < Storable.length v = f (v Storable.! i) <&> \a -> v Storable.// [(i, a)]+ | otherwise = pure v+ {-# INLINE ix #-}++instance Unbox a => Ixed (Unboxed.Vector a) where+ ix i f v+ | 0 <= i && i < Unboxed.length v = f (v Unboxed.! i) <&> \a -> v Unboxed.// [(i, a)]+ | otherwise = pure v+ {-# INLINE ix #-}++instance Ixed T.Text where+ ix e f s = case T.splitAt e s of+ (l, mr) -> case T.uncons mr of+ Nothing -> pure s+ Just (c, xs) -> f c <&> \d -> T.concat [l, T.singleton d, xs]+ {-# INLINE ix #-}++instance Ixed TL.Text where+ ix e f s = case TL.splitAt e s of+ (l, mr) -> case TL.uncons mr of+ Nothing -> pure s+ Just (c, xs) -> f c <&> \d -> TL.append l (TL.cons d xs)+ {-# INLINE ix #-}++instance Cons T.Text T.Text Char Char where+ _Cons f s = case T.uncons s of+ Just x -> uncurry T.cons <$> f x+ Nothing -> pure T.empty+ {-# INLINE _Cons #-}++instance Cons TL.Text TL.Text Char Char where+ _Cons f s = case TL.uncons s of+ Just x -> uncurry TL.cons <$> f x+ Nothing -> pure TL.empty+ {-# INLINE _Cons #-}++instance Snoc T.Text T.Text Char Char where+ _Snoc f s = if T.null s+ then pure T.empty+ else uncurry T.snoc <$> f (T.init s, T.last s)+ {-# INLINE _Snoc #-}++instance Snoc TL.Text TL.Text Char Char where+ _Snoc f s = if TL.null s+ then pure TL.empty+ else uncurry TL.snoc <$> f (TL.init s, TL.last s)+ {-# INLINE _Snoc #-}++instance Cons (Vector.Vector a) (Vector.Vector b) a b where+ _Cons f s = if Vector.null s+ then pure Vector.empty+ else uncurry Vector.cons <$> f (Vector.unsafeHead s, Vector.unsafeTail s)+ {-# INLINE _Cons #-}++instance (Prim a, Prim b) => Cons (Prim.Vector a) (Prim.Vector b) a b where+ _Cons f s = if Prim.null s+ then pure Prim.empty+ else uncurry Prim.cons <$> f (Prim.unsafeHead s, Prim.unsafeTail s)+ {-# INLINE _Cons #-}++instance (Storable a, Storable b) => Cons (Storable.Vector a) (Storable.Vector b) a b where+ _Cons f s = if Storable.null s+ then pure Storable.empty+ else uncurry Storable.cons <$> f (Storable.unsafeHead s, Storable.unsafeTail s)+ {-# INLINE _Cons #-}++instance (Unbox a, Unbox b) => Cons (Unboxed.Vector a) (Unboxed.Vector b) a b where+ _Cons f s = if Unboxed.null s+ then pure Unboxed.empty+ else uncurry Unboxed.cons <$> f (Unboxed.unsafeHead s, Unboxed.unsafeTail s)+ {-# INLINE _Cons #-}++instance Snoc (Vector.Vector a) (Vector.Vector b) a b where+ _Snoc f s = if Vector.null s+ then pure Vector.empty+ else uncurry Vector.snoc <$> f (Vector.unsafeInit s, Vector.unsafeLast s)+ {-# INLINE _Snoc #-}++instance (Prim a, Prim b) => Snoc (Prim.Vector a) (Prim.Vector b) a b where+ _Snoc f s = if Prim.null s+ then pure Prim.empty+ else uncurry Prim.snoc <$> f (Prim.unsafeInit s, Prim.unsafeLast s)+ {-# INLINE _Snoc #-}++instance (Storable a, Storable b) => Snoc (Storable.Vector a) (Storable.Vector b) a b where+ _Snoc f s = if Storable.null s+ then pure Storable.empty+ else uncurry Storable.snoc <$> f (Storable.unsafeInit s, Storable.unsafeLast s)+ {-# INLINE _Snoc #-}++instance (Unbox a, Unbox b) => Snoc (Unboxed.Vector a) (Unboxed.Vector b) a b where+ _Snoc f s = if Unboxed.null s+ then pure Unboxed.empty+ else uncurry Unboxed.snoc <$> f (Unboxed.unsafeInit s, Unboxed.unsafeLast s)+ {-# INLINE _Snoc #-}++instance Each (Vector.Vector a) (Vector.Vector b) a b where+ each = vectorTraverse+ {-# INLINE each #-}++instance (Prim a, Prim b) => Each (Prim.Vector a) (Prim.Vector b) a b where+ each = vectorTraverse+ {-# INLINE each #-}++instance (Storable a, Storable b) => Each (Storable.Vector a) (Storable.Vector b) a b where+ each = vectorTraverse+ {-# INLINE each #-}++instance (Unbox a, Unbox b) => Each (Unboxed.Vector a) (Unboxed.Vector b) a b where+ each = vectorTraverse+ {-# INLINE each #-}++instance (c ~ d) => Each (HashMap c a) (HashMap d b) a b where+ each = traversed+ {-# INLINE each #-} ++instance (a ~ Char, b ~ Char) => Each T.Text T.Text a b where+ each = strictText+ {-# INLINE each #-}++instance (a ~ Char, b ~ Char) => Each TL.Text TL.Text a b where+ each = lazyText+ {-# INLINE each #-}++strictUnpacked :: Lens' T.Text String+strictUnpacked f t = T.pack <$> f (T.unpack t)+{-# INLINE strictUnpacked #-}++strictText :: Traversal' T.Text Char+strictText = strictUnpacked . traversed+{-# INLINE [0] strictText #-}++{-# RULES+"strict text -> map" strictText = sets T.map :: ASetter' T.Text Char;+"strict text -> foldr" strictText = foldring T.foldr :: Getting (Endo r) T.Text Char;+ #-}++lazyUnpacked :: Lens' TL.Text String+lazyUnpacked f t = TL.pack <$> f (TL.unpack t)+{-# INLINE lazyUnpacked #-}++lazyText :: Traversal' TL.Text Char+lazyText = lazyUnpacked . traversed+{-# INLINE [0] lazyText #-}++{-# RULES+"lazy text -> map" lazyText = sets TL.map :: ASetter' TL.Text Char;+"lazy text -> foldr" lazyText = foldring TL.foldr :: Getting (Endo r) TL.Text Char;+ #-}++vectorTraverse :: (Generic.Vector v a, Generic.Vector w b) => Traversal (v a) (w b) a b+vectorTraverse f v = Generic.fromListN (Generic.length v) <$> traversed f (Generic.toList v)+{-# INLINE [0] vectorTraverse #-}++{-# RULES+"vectorTraverse -> mapped" vectorTraverse = sets Generic.map :: (Generic.Vector v a, Generic.Vector v b) => ASetter (v a) (v b) a b;+"vectorTraverse -> foldr" vectorTraverse = foldring Generic.foldr :: Generic.Vector v a => Getting (Endo r) (v a) a;+ #-}