packages feed

smash 0.1.0.0 → 0.1.1.0

raw patch · 6 files changed

+133/−33 lines, 6 filesdep +binarydep +deepseqdep −ghcflagsdep ~basedep ~bifunctorsdep ~hashablePVP ok

version bump matches the API change (PVP)

Dependencies added: binary, deepseq

Dependencies removed: ghcflags

Dependency ranges changed: base, bifunctors, hashable

API changes (from Hackage documentation)

+ Data.Can: instance (Control.DeepSeq.NFData a, Control.DeepSeq.NFData b) => Control.DeepSeq.NFData (Data.Can.Can a b)
+ Data.Can: instance (Data.Binary.Class.Binary a, Data.Binary.Class.Binary b) => Data.Binary.Class.Binary (Data.Can.Can a b)
+ Data.Smash: instance (Control.DeepSeq.NFData a, Control.DeepSeq.NFData b) => Control.DeepSeq.NFData (Data.Smash.Smash a b)
+ Data.Smash: instance (Data.Binary.Class.Binary a, Data.Binary.Class.Binary b) => Data.Binary.Class.Binary (Data.Smash.Smash a b)
+ Data.Wedge: instance (Control.DeepSeq.NFData a, Control.DeepSeq.NFData b) => Control.DeepSeq.NFData (Data.Wedge.Wedge a b)
+ Data.Wedge: instance (Data.Binary.Class.Binary a, Data.Binary.Class.Binary b) => Data.Binary.Class.Binary (Data.Wedge.Wedge a b)

Files

CHANGELOG.md view
@@ -1,5 +1,9 @@ # Revision history for possibly-can+## 0.1.1 -## 0.1.0.0 -- YYYY-mm-dd+* Add `NFData`, `Binary` instances+* CPP to extend to 8.2.2 without warnings++## 0.1.0.0  * First version. Released on an unsuspecting world.
README.md view
@@ -1,1 +1,40 @@-# Smash-core: smash products in Hask+# smash: Combinators for Maybe types++[![Build Status](https://travis-ci.com/emilypi/smash.svg?branch=master)](https://travis-ci.com/emilypi/smash)+[![Hackage](https://img.shields.io/hackage/v/smash.svg)](https://hackage.haskell.org/package/smash)++This package consists of 3 datatypes: [Wedge](https://hackage.haskell.org/package/smash/docs/Data-Wedge.html), [Can](https://hackage.haskell.org/package/smash/docs/Data-Can.html), and [Smash](https://hackage.haskell.org/package/smash/docs/Data-Smash.html).++You can imagine these three types as `Maybe (Either a b)`, `Maybe (Either a (Either b (a,b))`, and `Maybe (These a b)` respectively. It turns out that that each of these datatypes has spcial properties:++- the `Wedge` datatype represents the coproduct (like, `Either`) in the category Hask* of pointed Hask types, called a [wedge sum](https://ncatlab.org/nlab/show/wedge+sum). One can derive this by noting that units are the same in Haskell, and the sum of two pointed types is `(1 + a) + (1 + b) ~ 1 + a + b ~ Wedge a b`.++- the `Can` datatype represents the product (like, `(,)`) in Hask*. You can derive this by considering the product of two pointed types `(1 + a) * (1 + b) ~ 1 + a + b + a*b ~ Can a b`.++- the `Smash` datatype represents a special type of product, a+[smash product](https://ncatlab.org/nlab/show/smash+product), in the category Hask\*.  The smash product is a symmetric, monoidal tensor in Hask* that plays nicely with the product, 'Can', and coproduct, 'Wedge'.+++Pictorially, these datatypes look like this:++```+'Can':+        a+        |+Non +---+---+ (a,b)+        |+        b++'Wedge':+                a+                |+Nowhere +-------++                |+                b+++'Smash':+++Nada +--------+ (a,b)+```
smash.cabal view
@@ -2,7 +2,7 @@   name:                smash-version:             0.1.0.0+version:             0.1.1.0 synopsis:            Smash products - like 'These', but with a unit! description:   Smash products are like the 'These' datatype, only with a unit. You can@@ -30,37 +30,20 @@   location: https://github.com/emilypi/smash.git  -flag ghc-flags-  description: Generate .ghc.flags files during compilation-  manual:      True-  default:     False--flag perf-flags-  description: Performance tuning flags-  manual:      True-  default:     False- library   exposed-modules:     Data.Can                      , Data.Smash                      , Data.Wedge-  -- other-modules:-  -- other-extensions:-  build-depends:       base >=4.10 && <5.0-                     , bifunctors-                     , hashable +  build-depends:       base        >=4.10 && <5.0+                     , bifunctors ^>=5.5+                     , binary     ^>=0.8+                     , deepseq    ^>=1.4+                     , hashable   ^>=1.3+   hs-source-dirs:      src   default-language:    Haskell2010   ghc-options:         -Wall--  if flag(ghc-flags)-    build-tool-depends: hsinspect:hsinspect-    build-depends: ghcflags-    ghc-options: -fplugin GhcFlags.Plugin--  if flag(perf-flags)-    ghc-options: -ddump-simpl -ddump-to-file   test-suite tasty
src/Data/Can.hs view
@@ -1,9 +1,11 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE TupleSections #-} {-# LANGUAGE RankNTypes #-}+{-# LANGUAGE TypeApplications #-} -- | -- Module       : Data.Can -- Copyright    : (c) 2020 Emily Pillmore@@ -11,7 +13,7 @@ -- -- Maintainer   : Emily Pillmore <emilypi@cohomolo.gy> -- Stability    : Experimental--- Portability  : portable+-- Portability  : CPP, RankNTypes, TypeApplications -- -- This module contains the definition for the 'Can' datatype. In -- practice, this type is isomorphic to 'Maybe' 'These' - the type with@@ -62,14 +64,19 @@   import Control.Applicative (Alternative(..))+import Control.DeepSeq (NFData(..))  import Data.Bifunctor import Data.Bifoldable+import Data.Binary (Binary(..)) import Data.Bitraversable import Data.Data import qualified Data.Either as E import Data.Foldable import Data.Hashable+#if __GLASGOW_HASKELL__ < 804+import Data.Semigroup (Semigroup(..))+#endif  import GHC.Generics @@ -504,7 +511,27 @@  instance (Semigroup a, Semigroup b) => Monoid (Can a b) where   mempty = Non+  mappend = (<>) +instance (NFData a, NFData b) => NFData (Can a b) where+    rnf Non = ()+    rnf (One a) = rnf a+    rnf (Eno b) = rnf b+    rnf (Two a b) = rnf a `seq` rnf b++instance (Binary a, Binary b) => Binary (Can a b) where+  put Non = put @Int 0+  put (One a) = put @Int 1 >> put a+  put (Eno b) = put @Int 2 >> put b+  put (Two a b) = put @Int 3 >> put a >> put b++  get = get @Int >>= \case+    0 -> pure Non+    1 -> One <$> get+    2 -> Eno <$> get+    3 -> Two <$> get <*> get+    _ -> fail "Invalid Can index"+ -- -------------------------------------------------------------------- -- -- Bifunctors @@ -520,7 +547,7 @@     Non -> mempty     One a -> f a     Eno b -> g b-    Two a b -> f a <> g b+    Two a b -> f a `mappend` g b  instance Bitraversable Can where   bitraverse f g = \case
src/Data/Smash.hs view
@@ -1,9 +1,11 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TupleSections #-}+{-# LANGUAGE TypeApplications #-} -- | -- Module       : Data.Smash -- Copyright    : (c) 2020 Emily Pillmore@@ -11,7 +13,7 @@ -- -- Maintainer   : Emily Pillmore <emilypi@cohomolo.gy> -- Stability    : Experimental--- Portability  : portable+-- Portability  : CPP, RankNTypes, TypeApplications -- -- This module contains the definition for the 'Smash' datatype. In -- practice, this type is isomorphic to 'Maybe (a,b)' - the type with@@ -59,14 +61,21 @@   import Control.Applicative (Alternative(..))+import Control.DeepSeq (NFData(..))+ import Data.Bifunctor import Data.Bifoldable+import Data.Binary (Binary(..)) import Data.Bitraversable import Data.Can (Can(..), can) import Data.Data import Data.Hashable import Data.Wedge (Wedge(..))+#if __GLASGOW_HASKELL__ < 804+import Data.Semigroup (Semigroup(..))+#endif + import GHC.Generics  {- $general@@ -372,7 +381,7 @@    Nada <*> _ = Nada   _ <*> Nada = Nada-  Smash a f <*> Smash c d = Smash (a <> c) (f d)+  Smash a f <*> Smash c d = Smash (a `mappend` c) (f d)  instance Monoid a => Monad (Smash a) where   return = pure@@ -381,7 +390,7 @@   Nada >>= _ = Nada   Smash a b >>= k = case k b of     Nada -> Nada-    Smash c d -> Smash (a <> c) d+    Smash c d -> Smash (a `mappend` c) d  instance (Semigroup a, Semigroup b) => Semigroup (Smash a b) where   Nada <> b = b@@ -390,7 +399,21 @@  instance (Semigroup a, Semigroup b) => Monoid (Smash a b) where   mempty = Nada+  mappend = (<>) +instance (NFData a, NFData b) => NFData (Smash a b) where+  rnf Nada = ()+  rnf (Smash a b) = rnf a `seq` rnf b++instance (Binary a, Binary b) => Binary (Smash a b) where+  put Nada = put @Int 0+  put (Smash a b) = put @Int 1 >> put a >> put b++  get = get @Int >>= \case+    0 -> pure Nada+    1 -> Smash <$> get <*> get+    _ -> fail "Invalid Smash index"+ -- -------------------------------------------------------------------- -- -- Bifunctors @@ -402,7 +425,7 @@ instance Bifoldable Smash where   bifoldMap f g = \case     Nada -> mempty-    Smash a b -> f a <> g b+    Smash a b -> f a `mappend` g b  instance Bitraversable Smash where   bitraverse f g = \case
src/Data/Wedge.hs view
@@ -1,9 +1,11 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DeriveAnyClass #-} {-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveGeneric #-} {-# LANGUAGE LambdaCase #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE TupleSections #-}+{-# LANGUAGE TypeApplications #-} -- | -- Module       : Data.Wedge -- Copyright    : (c) 2020 Emily Pillmore@@ -11,7 +13,7 @@ -- -- Maintainer   : Emily Pillmore <emilypi@cohomolo.gy> -- Stability    : Experimental--- Portability  : portable+-- Portability  : CPP, RankNTypes, TypeApplications -- -- This module contains the definition for the 'Wedge' datatype. In -- practice, this type is isomorphic to 'Maybe (Either a b)' - the type with@@ -56,12 +58,17 @@   import Control.Applicative (Alternative(..))+import Control.DeepSeq (NFData(..))  import Data.Bifunctor import Data.Bifoldable+import Data.Binary (Binary(..)) import Data.Bitraversable import Data.Data import Data.Hashable+#if __GLASGOW_HASKELL__ < 804+import Data.Semigroup (Semigroup(..))+#endif  import GHC.Generics @@ -399,6 +406,23 @@  instance (Semigroup a, Semigroup b) => Monoid (Wedge a b) where   mempty = Nowhere+  mappend = (<>)++instance (NFData a, NFData b) => NFData (Wedge a b) where+    rnf Nowhere = ()+    rnf (Here a) = rnf a+    rnf (There b) = rnf b++instance (Binary a, Binary b) => Binary (Wedge a b) where+  put Nowhere = put @Int 0+  put (Here a) = put @Int 1 >> put a+  put (There b) = put @Int 2 >> put b++  get = get @Int >>= \case+    0 -> pure Nowhere+    1 -> Here <$> get+    2 -> There <$> get+    _ -> fail "Invalid Wedge index"  -- -------------------------------------------------------------------- -- -- Bifunctors