mono-traversable-wrapper (empty) → 0.1.0.0
raw patch · 4 files changed
+130/−0 lines, 4 filesdep +basedep +mono-traversablesetup-changed
Dependencies added: base, mono-traversable
Files
- LICENSE +19/−0
- Setup.hs +2/−0
- mono-traversable-wrapper.cabal +25/−0
- src/Data/MonoTraversable/Container.hs +84/−0
+ LICENSE view
@@ -0,0 +1,19 @@+Copyright Donnacha Oisín Kidney (c) 2017++Permission is hereby granted, free of charge, to any person obtaining a copy+of this software and associated documentation files (the "Software"), to deal+in the Software without restriction, including without limitation the rights+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell+copies of the Software, and to permit persons to whom the Software is+furnished to do so, subject to the following conditions:++The above copyright notice and this permission notice shall be included in+all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN+THE SOFTWARE.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ mono-traversable-wrapper.cabal view
@@ -0,0 +1,25 @@+name: mono-traversable-wrapper+version: 0.1.0.0+synopsis: Wrapper providing Foldable instance for MonoFoldables.+description: Please see README.md+homepage: https://github.com/oisdk/mono-traversable-compat+license: MIT+license-file: LICENSE+author: Donnacha Oisín Kidney+maintainer: mail@doisinkidney.com+copyright: 2016 Donnacha Oisín Kidney+category: Data+build-type: Simple+cabal-version: >=1.10++library+ hs-source-dirs: src+ exposed-modules: Data.MonoTraversable.Container+ build-depends: base >= 4.7 && < 5+ , mono-traversable >= 0.5+ default-language: Haskell2010+ ghc-options: -Wall++source-repository head+ type: git+ location: https://github.com/oisdk/mono-traversable-compat
+ src/Data/MonoTraversable/Container.hs view
@@ -0,0 +1,84 @@+{-# LANGUAGE GADTs #-}++-- | This module provides the 'Container' type, which wraps monomorphic types,+-- and makes them conform to the "Prelude"'s non-monomorphic typeclasses.+module Data.MonoTraversable.Container where++import Data.Foldable+import Data.MonoTraversable++import Text.Read++-- | This type can wrap a monomorphic type to allow it to conform to+-- 'Foldable'. For instance, the wrapper for 'Data.Text.Text' would be+-- defined as:+--+-- @type FoldableText = 'Container' 'Text' 'Char'@+--+-- Now, this type conforms to 'Foldable'.+data Container xs a b where+ -- | Can only construct when last type variable is equal to second.+ Container :: (a ~ b) => xs -> Container xs a b++-- | Selector for 'Container'+getContainer :: Container xs a b -> xs+getContainer (Container xs) = xs+{-# INLINE getContainer #-}++instance Eq xs => Eq (Container xs a b) where+ Container x == Container y = x == y+ {-# INLINE (==) #-}++instance Ord xs => Ord (Container xs a b) where+ compare (Container x) (Container y) = compare x y+ {-# INLINE compare #-}+ Container x < Container y = x < y+ {-# INLINE (<) #-}+ Container x >= Container y = x >= y+ {-# INLINE (>=) #-}+ Container x > Container y = x > y+ {-# INLINE (>) #-}+ Container x <= Container y = x <= y+ {-# INLINE (<=) #-}+ max (Container x) (Container y) = Container (max x y)+ {-# INLINE max #-}+ min (Container x) (Container y) = Container (min x y)+ {-# INLINE min #-}++instance Show xs => Show (Container xs a b) where+ showsPrec d (Container a) =+ showParen (d >= 11)+ $ showString "Container "+ . showsPrec 11 a++instance (Read xs, a ~ b) => Read (Container xs a b) where+ readPrec = parens $ prec 10 $ do+ Ident "Container" <- lexP+ Container <$> step (readS_to_Prec readsPrec)++instance (MonoFoldable xs, element ~ Element xs) =>+ Foldable (Container xs element) where+ foldr f b (Container xs) = ofoldr f b xs+ {-# INLINE foldr #-}+ foldMap f (Container xs) = ofoldMap f xs+ {-# INLINE foldMap #-}+ foldl' f b (Container xs) = ofoldl' f b xs+ {-# INLINE foldl' #-}+ toList (Container xs) = otoList xs+ {-# INLINE toList #-}+ null (Container xs) = onull xs+ {-# INLINE null #-}+ length (Container xs) = olength xs+ {-# INLINE length #-}+ foldr1 f (Container xs) = ofoldr1Ex f xs+ {-# INLINE foldr1 #-}+ elem x (Container xs) = oelem x xs+ {-# INLINE elem #-}+ maximum (Container xs) = maximumEx xs+ {-# INLINE maximum #-}+ minimum (Container xs) = minimumEx xs+ {-# INLINE minimum #-}+ sum (Container xs) = osum xs+ {-# INLINE sum #-}+ product (Container xs) = oproduct xs+ {-# INLINE product #-}