packages feed

barbies-layered (empty) → 0.1.0.0

raw patch · 9 files changed

+287/−0 lines, 9 filesdep +barbiesdep +barbies-layereddep +base

Dependencies added: barbies, barbies-layered, base, doctest, hspec, transformers

Files

+ CHANGELOG.md view
@@ -0,0 +1,10 @@+# Changelog for barbies-layered++## 0.1.0.0++*2021.07.16*++Initial release.++- `Barbies.Bare.Layered.BareB`+- `Data.Functor.Barbie.Layered.FunctorB`
+ LICENSE view
@@ -0,0 +1,46 @@+Copyright 2020 Kazuki Okamoto (岡本和樹)++Licensed under the Apache License, Version 2.0 (the "License");+you may not use this file except in compliance with the License.+You may obtain a copy of the License at++    http://www.apache.org/licenses/LICENSE-2.0++Unless required by applicable law or agreed to in writing, software+distributed under the License is distributed on an "AS IS" BASIS,+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.+See the License for the specific language governing permissions and+limitations under the License.++---------------------------------------------------------------------------++Copyright Daniel Gorin (c) 2018++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 Author name here 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.
+ README.md view
@@ -0,0 +1,41 @@+# barbies-layered++[![Hackage](https://matrix.hackage.haskell.org/api/v2/packages/barbies-layered/badge)](http://hackage.haskell.org/package/barbies-layered)++![CI](https://github.com/kakkun61/barbies-layered/workflows/main/badge.svg)++[![Sponsor](https://img.shields.io/badge/Sponsor-%E2%9D%A4-red?logo=GitHub)](https://github.com/sponsors/kakkun61)++This is like [barbies](https://hackage.haskell.org/package/barbies) but these clothes are layered.++For example when there is a following data type,++```haskell+data Foo = Foo { foo :: [Int] }+```++barbies requires a following.++```haskell+data Foo f = Foo { foo :: f [Int] }+```++But in case of barbies-layered,++```haskell+data Foo f = Foo { foo :: f [f Int] }+```++A typical difference is a type of `bmap`.++```haskell+-- barbies+type FunctorB :: ((k -> Type) -> Type) -> Constraint+class FunctorB b where+  bmap :: (forall a. f a -> g a) -> b f -> b g++-- barbies-layered+type FunctorB :: ((Type -> Type) -> Type) -> Constraint+class FunctorB b where+  bmap :: (Functor f, Functor g) => (forall a. f a -> g a) -> b f -> b g+```
+ barbies-layered.cabal view
@@ -0,0 +1,69 @@+cabal-version: 2.2++name: barbies-layered+version: 0.1.0.0+synopsis: Barbies with layered clothes.+description: Data with fields that are multiply covered with functors.+homepage: https://github.com/kakkun61/barbies-layered+bug-reports: https://github.com/kakkun61/barbies-layered/issues+license: Apache-2.0+license-file: LICENSE+author: Kazuki Okamoto (岡本和樹)+maintainer: kazuki.okamoto@kakkun61.com+copyright: 2021 Kazuki Okamoto (岡本和樹)+category: Data-structures+build-type: Simple+tested-with: GHC == 8.6.5, GHC == 8.8.4, GHC == 8.10.4, GHC == 9.0.1+extra-source-files: README.md,+                    CHANGELOG.md++common common+  build-depends: base >= 4 && < 5+  ghc-options: -Wall+               -Wcompat+  default-language: Haskell2010++library+  import: common+  hs-source-dirs: src+  exposed-modules: Barbies.Bare.Layered+                   Data.Functor.Barbie.Layered+  build-depends: barbies,+                 transformers+  ghc-options: -Wincomplete-uni-patterns+               -Wincomplete-record-updates+               -Wmonomorphism-restriction+               -Wmissing-exported-signatures+               -Wmissing-export-lists+               -Wmissing-home-modules+               -Wmissing-import-lists+               -Widentities+               -Wredundant-constraints+               -Wpartial-fields+               -Wno-name-shadowing++test-suite doctest+  import: common+  type: exitcode-stdio-1.0+  main-is: main.hs+  hs-source-dirs: test/doctest+  build-depends: barbies-layered,+                 doctest+  ghc-options: -threaded+               -rtsopts+               -with-rtsopts=-N+  build-tool-depends: doctest-discover:doctest-discover++test-suite spec+  import: common+  type: exitcode-stdio-1.0+  main-is: Spec.hs+  hs-source-dirs: test/spec+  other-modules: Barbies.Bare.LayeredSpec+  build-depends: barbies-layered,+                 barbies,+                 hspec+  ghc-options: -threaded+               -rtsopts+               -with-rtsopts=-N+  build-tool-depends: hspec-discover:hspec-discover
+ src/Barbies/Bare/Layered.hs view
@@ -0,0 +1,35 @@+{-# LANGUAGE RankNTypes #-}++module Barbies.Bare.Layered+  ( -- * Bare values+    Wear+  , Bare+  , Covered+    -- * Covering and stripping+  , BareB (bstrip, bcover)+  , bstripFrom+  , bcoverWith+  ) where++import Barbies.Bare                (Bare, Covered, Wear)+import Data.Functor.Barbie.Layered (FunctorB (bmap))+import Data.Functor.Identity       (Identity (Identity, runIdentity))++-- | Class of Barbie-types defined using 'Wear' and can therefore+-- have 'Bare' versions. Must satisfy:+--+-- @+-- 'bcover' . 'bstrip' = 'id'+-- 'bstrip' . 'bcover' = 'id'+-- @+class FunctorB (b Covered) => BareB b where+  bstrip :: b Covered Identity -> b Bare Identity+  bcover :: b Bare Identity -> b Covered Identity++-- | Generalization of 'bstrip' to arbitrary functors.+bstripFrom :: (BareB b, Functor f) => (forall a . f a -> a) -> b Covered f -> b Bare Identity+bstripFrom f = bstrip . bmap (Identity . f)++-- | Generalization of 'bcover' to arbitrary functors.+bcoverWith :: (BareB b, Functor f) => (forall a . a -> f a) -> b Bare Identity -> b Covered f+bcoverWith f = bmap (f . runIdentity) . bcover
+ src/Data/Functor/Barbie/Layered.hs view
@@ -0,0 +1,48 @@+{-# LANGUAGE RankNTypes               #-}++module Data.Functor.Barbie.Layered+  ( FunctorB (..)+  ) where++import Barbies               (Unit (Unit), Void)+import Data.Data             (Proxy (Proxy))+import Data.Functor.Compose  (Compose (Compose))+import Data.Functor.Const    (Const (Const))+import Data.Functor.Constant (Constant (Constant))+import Data.Functor.Product  (Product (Pair))+import Data.Functor.Sum      (Sum (InL, InR))++-- | Barbie-types that can be mapped over. Instances of 'FunctorB' should+-- satisfy the following laws:+--+-- @+-- 'bmap' 'id' = 'id'+-- 'bmap' f . 'bmap' g = 'bmap' (f . g)+-- @+class FunctorB b where+  bmap :: forall f g. (Functor f, Functor g) => (forall a. f a -> g a) -> b f -> b g++instance FunctorB Proxy where+  bmap _ _ = Proxy++instance FunctorB Void where+  bmap _ _ = undefined++instance FunctorB Unit where+  bmap _ _ = Unit++instance FunctorB (Constant a) where+  bmap _ (Constant a) = Constant a++instance FunctorB (Const a) where+  bmap _ (Const a) = Const a++instance (FunctorB a, FunctorB b) => FunctorB (Product a b) where+  bmap f (Pair x y) = Pair (bmap f x) (bmap f y)++instance (FunctorB a, FunctorB b) => FunctorB (Sum a b) where+  bmap f (InL x) = InL (bmap f x)+  bmap f (InR x) = InR (bmap f x)++instance (Functor f, FunctorB b) => FunctorB (Compose f b) where+  bmap h (Compose x) = Compose (bmap h <$> x)
+ test/doctest/main.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF doctest-discover #-}
+ test/spec/Barbies/Bare/LayeredSpec.hs view
@@ -0,0 +1,36 @@+{-# LANGUAGE AllowAmbiguousTypes  #-}+{-# LANGUAGE DeriveFunctor        #-}+{-# LANGUAGE FlexibleContexts     #-}+{-# LANGUAGE FlexibleInstances    #-}+{-# LANGUAGE StandaloneDeriving   #-}+{-# LANGUAGE UndecidableInstances #-}++module Barbies.Bare.LayeredSpec where++import Barbies.Bare.Layered+import Data.Functor.Barbie.Layered++import Data.Functor.Identity+import Test.Hspec++spec :: Spec+spec = do+  it "bstripFrom" $ do+    bstripFrom runBar (Foo (Bar 1)) `shouldBe` Foo 1++  it "bcoverWith" $ do+    bcoverWith Bar (Foo 1) `shouldBe` Foo (Bar 1)++newtype Foo b f = Foo (Wear b f Int)++deriving instance Show (Wear b f Int) => Show (Foo b f)+deriving instance Eq (Wear b f Int) => Eq (Foo b f)++instance FunctorB (Foo Covered) where+  bmap f (Foo a) = Foo (f a)++instance BareB Foo where+  bstrip (Foo (Identity a)) = Foo a+  bcover (Foo a) = Foo $ Identity a++newtype Bar a = Bar { runBar :: a } deriving (Show, Eq, Functor)
+ test/spec/Spec.hs view
@@ -0,0 +1,1 @@+{-# OPTIONS_GHC -F -pgmF hspec-discover #-}