packages feed

data-diverse 0.10.0.0 → 0.11.0.0

raw patch · 5 files changed

+76/−63 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.Diverse.Which: zilch :: Which '[]
- Data.Diverse.Which.Internal: instance Data.Diverse.Reduce.Reduce (Data.Diverse.Which.Internal.Which '[]) (Data.Diverse.Which.Internal.Switcher (Data.Diverse.Which.Internal.CaseDiversify '[] '[]) '[] (Data.Diverse.Which.Internal.Which '[]))
- Data.Diverse.Which.Internal: instance Data.Diverse.Reduce.Reduce (Data.Diverse.Which.Internal.Which '[]) (Data.Diverse.Which.Internal.Switcher (Data.Diverse.Which.Internal.CaseReinterpret '[] '[]) '[] (Data.Either.Either (Data.Diverse.Which.Internal.Which '[]) (Data.Diverse.Which.Internal.Which '[])))
- Data.Diverse.Which.Internal: instance Data.Diverse.Reduce.Reduce (Data.Diverse.Which.Internal.Which '[]) (Data.Diverse.Which.Internal.Switcher (Data.Diverse.Which.Internal.CaseReinterpret' '[] '[]) '[] (GHC.Base.Maybe (Data.Diverse.Which.Internal.Which '[])))
- Data.Diverse.Which.Internal: instance GHC.Base.Monoid (Data.Diverse.Which.Internal.Which '[])
- Data.Diverse.Which.Internal: zilch :: Which '[]
+ Data.Diverse.Which: impossible :: Which '[] -> a
+ Data.Diverse.Which.Internal: impossible :: Which '[] -> a
+ Data.Diverse.Which.Internal: instance Data.Diverse.Reduce.Reduce (Data.Diverse.Which.Internal.Which '[]) (Data.Diverse.Which.Internal.Switcher c '[] r)

Files

README.md view
@@ -50,15 +50,23 @@   - Fixed GHC 8.2.1 test failure due to changed TypeRep show instance.  * 0.10.0.0-  - Renamed 'Switch' to 'Switcher'. Switch is now a type synonym for 'switch' constraints-  - Added CasesResult type family to help infer the result of 'cases'+  - Renamed `Switch` to `Switcher`. Switch is now a type synonym for `switch` constraints+  - Added CasesResult type family to help infer the result of `cases`   - Added Semigroup and Monoid instances for all Many xs.   - Added Maybe versions of trial, and reinterpret-  - Renamed 'reinterpetN' to 'reinterpretN''-  - Renamed 'impossible' to 'zilch'.-  - Allowed 'reintepret'ing and 'diversify'ing 'zilch' to 'zilch'-  - Removed zipped type variable from 'Amend' constraints.-  - Removed r type variable from 'Reduce' typeclass.-  - Rearranged type variables in 'fetch', 'replace', 'pick', 'trial', 'Diversify' type parameters,+  - Renamed `reinterpetN` to `reinterpretN'`+  - Renamed `impossible` to `zilch`.+  - Allowed `reintepret`ing and `diversify`ing `zilch` to `zilch`+  - Removed zipped type variable from `Amend` constraints.+  - Removed r type variable from `Reduce` typeclass.+  - Rearranged type variables in `fetch`, `replace`, `pick`, `trial`, `Diversify` type parameters,     so the type variable ordering is consistently smaller to larger, ie. 'x', 'xs', 'branch', 'tree'-  - Added 'diversify'' for allowing rearranging the types only.+  - Added `diversify'` for allowing rearranging the types only.++* 0.11.0.0+  - Fixed https://github.com/louispan/data-diverse/issues/4+  - Added `impossible` modelled after `Data.Void.absurd`+  - Removed `zilch` so `Which '[]` is uninhabited like `Data.Void.Void`, making 'impossible' safe to use.+  - Removed `Monoid` and changed `Show`, `Read` and `Generic` instances for `Which '[]` to be partial+    just like Data.Void.Void.+  - Added instance Reduce (Which '[]) (Switcher c '[] r), which follows from 'impossible'.
data-diverse.cabal view
@@ -1,5 +1,5 @@ name:                data-diverse-version:             0.10.0.0+version:             0.11.0.0 synopsis:            Extensible records and polymorphic variants. description:         "Data.Diverse.Many" is an extensible record for any size encoded efficiently as (Seq Any).                      "Data.Diverse.Which" is a polymorphic variant of possibilities encoded as (Int, Any).
src/Data/Diverse/Which.hs view
@@ -5,7 +5,7 @@        -- * Single type       -- ** Construction-    , zilch+    , impossible     , pick     , pick0     , pickOnly
src/Data/Diverse/Which/Internal.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-}+{-# LANGUAGE EmptyCase #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-}@@ -19,7 +20,7 @@        -- * Single type       -- ** Construction-    , zilch+    , impossible     , pick     , pick0     , pickOnly@@ -129,9 +130,9 @@ -- | A terminating 'G.Generic' instance for no types encoded as a 'zilch'. -- The 'G.C1' and 'G.S1' metadata are not encoded. instance G.Generic (Which '[]) where-  type Rep (Which '[]) = G.U1-  from _ = {- G.U1 -} G.U1-  to G.U1 = zilch+    type Rep (Which '[]) = G.V1+    from _ = {- G.V1 -} error "No generic representation for Which '[]"+    to _ = error "No values for Which '[]"  -- | A terminating 'G.Generic' instance for one type encoded with 'pick''. -- The 'G.C1' and 'G.S1' metadata are not encoded.@@ -154,18 +155,19 @@ -----------------------------------------------------------------------  instance Semigroup (Which '[]) where-    _ <> _ = zilch--instance Monoid (Which '[]) where-    mempty = zilch-    mappend = (<>)+    a <> _ = a --- | A 'Which' with no alternatives. You can't do anything with 'zilch'--- except Eq, Read, and Show it.--- Using functions like 'switch' and 'trial' with 'zilch' is a compile error.--- 'zilch' is useful as a 'Left'-over from 'trial'ing a @Which '[x]@ with one type.-zilch :: Which '[]-zilch = Which (-1) (unsafeCoerce ())+-- | Analogous to 'Data.Void.absurd'. Renamed 'impossible' to avoid conflicts.+--+-- Since 'Which \'[]' values logically don't exist, this witnesses the+-- logical reasoning tool of \"ex falso quodlibet\",+-- ie "from falsehood, anything follows".+--+-- A 'Which \'[]' is a 'Which' with no alternatives, which may occur as a 'Left'-over from 'trial'ing a @Which '[x]@ with one type.+-- It is an uninhabited type, just like 'Data.Void.Void'+impossible :: Which '[] -> a+impossible a = case a of {}+-- Copied from http://hackage.haskell.org/package/base/docs/src/Data.Void.html  -- | Lift a value into a 'Which' of possibly other types @xs@. -- @xs@ can be inferred or specified with TypeApplications.@@ -339,12 +341,12 @@ -- -- It is a compile error if @tree@ has duplicate types with @branch@. ----- NB. forall is used to @tree@ is ordered first, so TypeApplications can be used to specify @tree@ first.+-- NB. Use TypeApplications with @_ to specify @tree@. -- -- @ -- let a = 'pick'' (5 :: Int) :: 'Which' '[Int]---     b = 'diversify' \@[Int, Bool] a :: 'Which' '[Int, Bool]---     c = 'diversify' \@[Bool, Int] b :: 'Which' '[Bool, Int]+--     b = 'diversify' \@_ \@[Int, Bool] a :: 'Which' '[Int, Bool]+--     c = 'diversify' \@_ \@[Bool, Int] b :: 'Which' '[Bool, Int] -- @ diversify :: forall branch tree. Diversify branch tree => Which branch -> Which tree diversify = which (CaseDiversify @branch @tree @branch)@@ -405,8 +407,8 @@ -- -- @ -- let y = 'pickOnly' (5 :: Int)---     y' = 'diversifyN' \@'[0] \@[Int, Bool] Proxy y---     y'' = 'diversifyN' \@[1,0] \@[Bool, Int] Proxy y'+--     y' = 'diversifyN' \@'[0] \@_ \@[Int, Bool] Proxy y+--     y'' = 'diversifyN' \@[1,0] \@_ \@[Bool, Int] Proxy y' -- 'switch' y'' ('Data.Diverse.CaseTypeable.CaseTypeable' (show . typeRep . (pure \@Proxy))) \`shouldBe` \"Int" -- @ diversifyN :: forall indices branch tree proxy. (DiversifyN indices branch tree) => proxy indices -> Which branch -> Which tree@@ -581,17 +583,13 @@     reduce (Switcher c) v = case obvious v of             a -> case' c a --- | Allow 'zilch' to be 'reinterpret''ed into 'zilch'-instance Reduce (Which '[]) (Switcher (CaseReinterpret' '[] '[]) '[] (Maybe (Which '[]))) where-    reduce _ = Just---- | Allow 'zilch' to be 'reinterpret'ed into 'zilch'-instance Reduce (Which '[]) (Switcher (CaseReinterpret '[] '[]) '[] (Either (Which '[]) (Which '[]))) where-    reduce _ = Right+-- | Allow 'Which \'[]' to be 'reinterpret''ed or 'diversify'ed into anything else+-- This is safe because @Which '[]@ is uninhabited, and this is already something that+-- can be done with 'impossible'+instance Reduce (Which '[]) (Switcher c '[] r) where+    reduce _ = impossible --- | Allow 'zilch' to be 'diversify'ed into 'zilch'-instance Reduce (Which '[]) (Switcher (CaseDiversify '[] '[]) '[] (Which '[])) where-    reduce _ = id+------------------------------------------------------------------  -- | A friendlier constraint synonym for 'switch'. type Switch case' xs r = Reduce (Which xs) (Switcher case' xs r)@@ -730,10 +728,8 @@     showsPrec d v = showParen (d > app_prec) (which (CaseShowWhich 0) v)       where app_prec = 10 --- | @read "zilch" == 'zilch'@ instance Show (Which '[]) where-    showsPrec d _ = showParen (d > app_prec) (showString "zilch")-      where app_prec = 10+    showsPrec _ = impossible  newtype CaseShowWhich (xs :: [Type]) r = CaseShowWhich Int @@ -781,11 +777,7 @@       where         app_prec = 10 --- | @read "zilch" == 'zilch'@+-- | Reading a 'Which '[]' value is always a parse error, considering+-- 'Which '[]' as a data type with no constructors. instance Read (Which '[]) where-    readPrec =-        parens $ prec app_prec $ do-            lift $ L.expect (Ident "zilch")-            pure zilch-      where-        app_prec = 10+    readsPrec _ _ = []
test/Data/Diverse/WhichSpec.hs view
@@ -40,14 +40,13 @@             let s = "pickN @0 Proxy 5"                 x = read s :: Which '[Int, Bool]             show x `shouldBe` s-            "zilch" `shouldBe` show zilch-            "zilch" `shouldBe` show (read "zilch" :: Which '[])+            -- "zilch" `shouldBe` show zilch+            -- "zilch" `shouldBe` show (read "zilch" :: Which '[])          it "is an Eq" $ do             let y = pick (5 :: Int) :: Which '[Int, Bool]             let y' = pick (5 :: Int) :: Which '[Int, Bool]             y `shouldBe` y'-            read (show zilch) `shouldBe` zilch          it "is an Ord" $ do             let y5 = pick (5 :: Int) :: Which '[Int, Bool]@@ -55,7 +54,6 @@             compare y5 y5 `shouldBe` EQ             compare y5 y6 `shouldBe` LT             compare y6 y5 `shouldBe` GT-            compare zilch zilch `shouldBe` EQ          it "can be constructed by type with 'pick' and destructed with 'trial'" $ do             let y = pick (5 :: Int) :: Which '[Bool, Int, Char]@@ -94,7 +92,7 @@             trial @Int c `shouldBe` Right 5             trial @String c `shouldBe` Left d             trial @Int d `shouldBe` Right 5-            trial @Int d `shouldNotBe` Left zilch+            -- trial @Int d `shouldNotBe` Left zilch             obvious d `shouldBe` 5          it "can be 'trialN'led until its final 'obvious' value" $ do@@ -127,7 +125,7 @@             trial0 e `shouldBe` Left f              trial @Int f `shouldBe` Right 5-            trial @Int f `shouldNotBe` Left zilch+            -- trial @Int f `shouldNotBe` Left zilch             trial0 f `shouldBe` Right 5             obvious f `shouldBe` 5 @@ -241,18 +239,33 @@ #endif             (show . typeRep . (pure @Proxy) $ y) `shouldBe` expected -        it "is a compile error to 'trial', 'diversify', 'reinterpret from non-zilch to 'zilch'" $ do+        -- it "is a compile error to 'trial', 'diversify', 'reinterpret from non-zilch to 'zilch'" $ do             -- let a = diversify @[Int, Bool] zilch             -- let a = trial @Int zilch             -- let a = trialN (Proxy @0) zilch             -- let a = reinterpret @[Int, Bool] zilch             -- let a = reinterpretN (Proxy @'[0]) zilch-            zilch `shouldBe` zilch+            -- zilch `shouldBe` zilch -        it "is ok to 'reinterpret' and 'diversity' into 'zilch'" $ do+        it "is ok to 'reinterpret' and 'diversity' from Which '[]" $ do             let x = pick @_ @'[Int] (5 :: Int)+            case trial @Int x of+                Right y -> y `shouldBe` y+                Left zilch -> do+                    -- Which '[] can be diversified into anything+                    -- This is safe because Which '[] is uninhabited like Data.Void+                    -- and so like Data.Void.absurd, "if given a falsehood, anything follows"+                    diversify @'[] @'[Int, Bool] zilch `shouldBe` impossible zilch+                    reinterpret' @'[] zilch `shouldBe` Just zilch+                    reinterpret @'[] zilch `shouldBe` Right zilch+                    diversify @'[] zilch `shouldBe` zilch+                    read (show zilch) `shouldBe` zilch+                    compare zilch zilch `shouldBe` EQ             reinterpret' @'[] x `shouldBe` Nothing-            reinterpret' @'[] zilch `shouldBe` Just zilch             reinterpret @'[] x `shouldBe` Left x-            reinterpret @'[] zilch `shouldBe` Right zilch-            diversify @'[] zilch `shouldBe` zilch++        it "'impossible' is just like 'absurd'. Once given an impossible Which '[], anything follows" $ do+            let x = pick @_ @'[Int] (5 :: Int)+            case trial @Int x of+                Right y -> y `shouldBe` y+                Left zilch -> impossible zilch