packages feed

newtype-generics 0.5 → 0.5.0.1

raw patch · 4 files changed

+108/−7 lines, 4 filesdep +newtype-genericsdep ~HUnitdep ~basedep ~hspecnew-uploaderPVP ok

version bump matches the API change (PVP)

Dependencies added: newtype-generics

Dependency ranges changed: HUnit, base, hspec

API changes (from Hackage documentation)

Files

+ CHANGELOG.md view
@@ -0,0 +1,2 @@+* 0.5.0.1 - Compatibility with GHC 8.2.1+* 0.5 - Relax types of underF and overF to allow different input & output funtors
+ README.md view
@@ -0,0 +1,38 @@+newtype-generics+================++A typeclass and set of functions for working with newtypes.+Fork of the code published by Darius Jahandarie [here](http://hackage.haskell.org/package/newtype-0.2),+with the addition of generics.++The 'Newtype' typeclass and related functions: `op`, `ala`, `ala'`, `under`. +Primarly pulled from Conor McBride's Epigram work. Some examples:++```+-- foldMaps the list ala the Sum newtype. This results in 10.+ala Sum foldMap [1,2,3,4] ++-- foldMaps the list ala the Product newtype. This results in 24.+ala Product foldMap [1,2,3,4] ++-- foldMaps the list ala the Endo newtype. This results in 8.+ala Endo foldMap [(+1), (+2), (subtract 1), (*2)] 3 +```++_NB:_ `Data.Foldable.foldMap` is a generalized `mconcatMap` which is a generalized `concatMap`.++This package includes `Newtype` instances for all the (non-GHC/foreign) newtypes in base (as seen in the examples).+However, there are neat things you can do with this with /any/ newtype and you should definitely define your own 'Newtype' instances for the power of this library.+For example, see `ala Cont traverse`, with the proper `Newtype` instance for Cont.++This could of course be eased with the addition of generics for version 0.3:++```+{-# LANGUAGE DeriveGeneric              #-}++import GHC.Generics+(...)+newtype Example = Example Int (deriving Generic)+instance Newtype Example+```+
newtype-generics.cabal view
@@ -1,5 +1,5 @@ Name:                newtype-generics-Version:             0.5+Version:             0.5.0.1 Synopsis:            A typeclass and set of functions for working with newtypes, with generics support. Description:         Per Conor McBride, the Newtype typeclass represents the packing and unpacking of a newtype,                      and allows you to operatate under that newtype with functions such as ala.@@ -8,16 +8,22 @@ License:             BSD3 License-file:        LICENSE Author:              Darius Jahandarie, Conor McBride, João Cristóvão-Maintainer:          João Cristóvão <jmacristovao@gmail.com>+Maintainer:          Simon Jakobi <simon.jakobi@gmail.com> -- Copyright:            Category:            Control Build-type:          Simple--- Extra-source-files:  +Extra-source-files:  CHANGELOG.md, README.md Cabal-version:       >=1.10+Tested-with:+  GHC==8.2.1,+  GHC==8.0.2,+  GHC==7.10.3,+  GHC==7.8.4,+  GHC==7.6.3  Library   Exposed-modules:     Control.Newtype-  Build-depends:       base >= 4.6 && < 4.10+  Build-depends:       base >= 4.6 && < 4.11   -- Other-modules:          -- Build-tools:            Ghc-options: -Wall@@ -30,8 +36,11 @@ test-suite test   type:               exitcode-stdio-1.0   main-is:            main.hs-  hs-source-dirs:     test,.+  hs-source-dirs:     test+  other-modules:      Control.NewtypeSpec   build-depends:      base-                    , hspec             >= 2.1 && < 2.4-                    , HUnit             >= 1.2.5.2 && < 1.6+                    , newtype-generics+                    , hspec             >= 2.1 && < 2.5+                    , HUnit             >= 1.2.5.2 && < 1.7   default-language:   Haskell2010+  build-tool-depends: hspec-discover:hspec-discover >= 2.1 && <2.5
+ test/Control/NewtypeSpec.hs view
@@ -0,0 +1,52 @@+{-# LANGUAGE NoMonomorphismRestriction #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE DeriveGeneric #-}+{-# LANGUAGE OverloadedStrings #-}+{-# LANGUAGE TypeFamilies #-}++module Control.NewtypeSpec where++import Prelude++import Data.Monoid+import Control.Newtype+import GHC.Generics++import Test.Hspec++newtype TestNewType = TestNewType Int deriving (Eq,Show,Generic)++instance Newtype TestNewType++{-# ANN spec ("HLint: ignore Redundant do"::String) #-}+spec :: Spec+spec = describe "Newtype test" $ do+  let four = 4 :: Int+      five = 5 :: Int+      noth = Nothing  :: Maybe String+  it "pack" $ do+    (pack True :: All)              `shouldBe` All True+    (pack True :: Any)              `shouldBe` Any True+    (pack (Just five) :: First Int) `shouldBe` First (Just 5)++  it "unpack" $ do+    unpack (Any False)          `shouldBe` False+    unpack (First (Just five))  `shouldBe` Just five+    unpack (Last noth)          `shouldBe` Nothing+    unpack (TestNewType five)   `shouldBe` five++  it "op" $ do+    op All (All True)  `shouldBe` True+    op Any (Any False) `shouldBe` False+    op Sum (Sum five)  `shouldBe` five++  it "under" $ do+    let sumLess (Sum x) = Sum (x - 1)+        firstN  (_)     = First Nothing+    under Sum   sumLess five        `shouldBe` four+    under First firstN  (Just five) `shouldBe` (Nothing :: Maybe Int)++  it "over" $ do+    over Sum     (+1) (Sum     four) `shouldBe` Sum five+    over Product (+1) (Product four) `shouldBe` Product five+