packages feed

haskus-utils-data 1.4 → 1.5

raw patch · 6 files changed

+33/−56 lines, 6 filesdep −doctestPVP ok

version bump matches the API change (PVP)

Dependencies removed: doctest

API changes (from Hackage documentation)

- Haskus.Utils.HList: instance (GHC.Show.Show e, GHC.Show.Show (Haskus.Utils.HList.HList l)) => GHC.Show.Show (Haskus.Utils.HList.HList (e : l))
- Haskus.Utils.HList: instance GHC.Show.Show (Haskus.Utils.HList.HList '[])
- Haskus.Utils.Tuple: instance Haskus.Utils.Tuple.ReorderTuple (Haskus.Utils.Tuple.Solo a) (Haskus.Utils.Tuple.Solo a)
- Haskus.Utils.Tuple: instance Haskus.Utils.Tuple.TupleCons a (Haskus.Utils.Tuple.Solo b) (a, b)
- Haskus.Utils.Tuple: instance Haskus.Utils.Tuple.TupleTail (a, b) (Haskus.Utils.Tuple.Solo b)
- Haskus.Utils.Tuple: type Solo = Unit
+ Haskus.Utils.HList: instance (GHC.Show.Show e, Haskus.Utils.HList.ShowHList l) => Haskus.Utils.HList.ShowHList (e : l)
+ Haskus.Utils.HList: instance Haskus.Utils.HList.ShowHList '[]
+ Haskus.Utils.HList: instance Haskus.Utils.HList.ShowHList l => GHC.Show.Show (Haskus.Utils.HList.HList l)
+ Haskus.Utils.Tuple: MkSolo :: a -> Solo a
+ Haskus.Utils.Tuple: data () => Solo a
+ Haskus.Utils.Tuple: instance Haskus.Utils.Tuple.ReorderTuple (Solo a) (Solo a)
+ Haskus.Utils.Tuple: instance Haskus.Utils.Tuple.TupleCons a (Solo b) (a, b)
+ Haskus.Utils.Tuple: instance Haskus.Utils.Tuple.TupleTail (a, b) (Solo b)
- Haskus.Utils.HList: hHead :: HList (e : l) -> e
+ Haskus.Utils.HList: hHead :: HList (e ': l) -> e
- Haskus.Utils.HList: hTail :: HList (e : l) -> HList l
+ Haskus.Utils.HList: hTail :: HList (e ': l) -> HList l
- Haskus.Utils.List: head :: [a] -> a
+ Haskus.Utils.List: head :: HasCallStack => [a] -> a
- Haskus.Utils.List: tail :: [a] -> [a]
+ Haskus.Utils.List: tail :: HasCallStack => [a] -> [a]

Files

haskus-utils-data.cabal view
@@ -1,15 +1,15 @@+cabal-version:       2.4 name:                haskus-utils-data-version:             1.4+version:             1.5 synopsis:            Haskus data utility modules-license:             BSD3+license:             BSD-3-Clause license-file:        LICENSE author:              Sylvain Henry maintainer:          sylvain@haskus.fr homepage:            http://www.haskus.org-copyright:           Sylvain Henry 2020+copyright:           Sylvain Henry 2024 category:            Data build-type:          Simple-cabal-version:       1.20  description:    Haskus data utility modules@@ -17,6 +17,7 @@ source-repository head   type: git   location: git://github.com/haskus/packages.git+  subdir:  haskus-utils-data  library   exposed-modules:@@ -55,4 +56,3 @@     build-depends:          base >= 4.9 && < 5-      ,  doctest
src/lib/Haskus/Utils/Functor.hs view
@@ -63,7 +63,6 @@ import Data.Functor.Sum import Data.Functor.Product import Control.Monad-import Control.Applicative  import Haskus.Utils.Types (Type) 
src/lib/Haskus/Utils/HList.hs view
@@ -36,6 +36,7 @@  import Haskus.Utils.Tuple import Haskus.Utils.Types+import qualified Data.List as List  -- | Heterogeneous list data family HList (l :: [Type])@@ -50,15 +51,18 @@ deriving instance Ord (HList '[]) deriving instance (Ord x, Ord (HList xs)) => Ord (HList (x ': xs)) +class ShowHList a where+  show_hlist :: HList a -> [String] -instance Show (HList '[]) where-    show _ = "H[]"+instance ShowHList '[] where+    show_hlist _ = [] -instance (Show e, Show (HList l)) => Show (HList (e ': l)) where-    show (HCons x l) = let 'H':'[':s = show l-                       in "H[" ++ show x ++-                                  (if s == "]" then s else "," ++ s)+instance (Show e, ShowHList l) => ShowHList (e ': l) where+    show_hlist (HCons x l) = show x : show_hlist l +instance ShowHList l => Show (HList l) where+    show l = "H[" ++ concat (List.intersperse "," (show_hlist l)) ++ "]"+ -- | Head hHead :: HList (e ': l) -> e hHead (HCons x _) = x@@ -212,8 +216,8 @@  instance HTuple '[a] where    hToTuple (a `HCons` HNil)-      = Solo a-   hFromTuple (Solo a)+      = MkSolo a+   hFromTuple (MkSolo a)       = a `HCons` HNil  instance HTuple '[a,b] where
src/lib/Haskus/Utils/List.hs view
@@ -1,5 +1,6 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE BangPatterns #-}+{-# LANGUAGE LambdaCase #-}  -- | List utils module Haskus.Utils.List@@ -59,6 +60,7 @@ import Data.Bifunctor import Data.Function (on) import qualified Data.List as L+import qualified Data.List.NonEmpty as NE  -- | Safely index into a list --@@ -146,7 +148,7 @@  -- | Get members of a bounded enum in a list ----- >>> :set -XTypeApplications+-- >>> :seti -XTypeApplications -- >>> data Letters = A | B | C | D deriving (Bounded,Enum,Show) -- >>> enumList @Letters -- [A,B,C,D]@@ -229,9 +231,13 @@ -- > split (== ':') "::xyz:abc::123::" == ["","","xyz","abc","","123","",""] -- > split (== ',') "my,list,here" == ["my","list","here"] split :: (a -> Bool) -> [a] -> [[a]]-split _ [] = [[]]-split f (x:xs) | f x                   = [] : split f xs-split f (x:xs) | ~(y:ys) <- split f xs = (x:y) : ys+split f xs = NE.toList (splitNE f xs)++splitNE :: (a -> Bool) -> [a] -> NE.NonEmpty [a]+splitNE f = \case+  []                                  -> []    NE.:| []+  (x:xs) | f x                        -> []    NE.:| split f xs+         | y NE.:| ys <- splitNE f xs -> (x:y) NE.:| ys  -- | Find the first instance of @needle@ in @haystack@. -- The first element of the returned tuple
src/lib/Haskus/Utils/Tuple.hs view
@@ -29,7 +29,7 @@    , take4    , fromTuple4    , module Data.Tuple-   , Solo, pattern Solo+   , Solo (..)    , Tuple    , Tuple#    , TypeReps@@ -47,13 +47,6 @@ import Data.Tuple import Haskus.Utils.Types -#if !MIN_VERSION_base(4,15,0)-type Solo = Unit-{-# COMPLETE Solo #-}-pattern Solo :: a -> Solo a-pattern Solo a = Unit a-#endif- -- | Uncurry3 uncurry3 :: (a -> b -> c -> r) -> (a,b,c) -> r {-# INLINABLE uncurry3 #-}@@ -99,7 +92,7 @@  instance ExtractTuple 0 '[a] where    {-# INLINABLE tupleN #-}-   tupleN (Solo t) = t+   tupleN (MkSolo t) = t  instance ExtractTuple 0 '[e0,e1] where    {-# INLINABLE tupleN #-}@@ -254,7 +247,7 @@  instance TupleTail (a,b) (Solo b) where    {-# INLINABLE tupleTail #-}-   tupleTail (_,b) = Solo b+   tupleTail (_,b) = MkSolo b  instance TupleTail (a,b,c) (b,c) where    {-# INLINABLE tupleTail #-}@@ -279,7 +272,7 @@  instance TupleCons a (Solo b) (a,b) where    {-# INLINABLE tupleCons #-}-   tupleCons a (Solo b) = (a,b)+   tupleCons a (MkSolo b) = (a,b)  instance TupleCons a (b,c) (a,b,c) where    {-# INLINABLE tupleCons #-}@@ -471,7 +464,7 @@    tupleCon = ()  instance TupleCon '[a] where-   tupleCon = Solo+   tupleCon = MkSolo  instance TupleCon '[a,b] where    tupleCon = (,)
src/tests/Main.hs view
@@ -1,27 +1,2 @@-{-# LANGUAGE LambdaCase #-}--import Test.DocTest--import Control.Exception-import System.Exit- main :: IO ()-main = wrapTests-   [ title "DOCTEST" $ doctest ["src/lib/"]-   ]--title :: String -> IO () -> IO ()-title s m = do-   putStrLn ""-   putStrLn (replicate 30 '=')-   putStrLn s-   putStrLn (replicate 30 '=')-   m--wrap :: IO () -> IO Bool-wrap m = (m >> return True) `catch` (\e -> return (e == ExitSuccess))--wrapTests :: [IO ()] -> IO ()-wrapTests ts = (and <$> traverse wrap ts) >>= \case-   True  -> title "SUMMARY" exitSuccess-   False -> title "SUMMARY" exitFailure+main = pure ()