packages feed

predicate-typed 0.7.4.0 → 0.7.4.1

raw patch · 25 files changed

+165/−319 lines, 25 filesdep +th-lift-instancesdep −random

Dependencies added: th-lift-instances

Dependencies removed: random

Files

predicate-typed.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: db15387a70ddf9d1c952bbab2f258515c9ac6ba98285247c865cb0e19e3618a0+-- hash: 27025abbd4f913bb4b084f90b828539a965ba7c0b7b1eaada9454db7c0542abe  name:           predicate-typed-version:        0.7.4.0+version:        0.7.4.1 synopsis:       Predicates, Refinement types and Dsl description:    Please see the README on GitHub at <https://github.com/gbwey/predicate-typed#readme> category:       Data@@ -87,12 +87,12 @@     , pcre-heavy >=1.0.0.2     , pcre-light     , pretty-terminal >=0.1.0.0-    , random     , safe     , string-conversions     , template-haskell     , text     , th-lift+    , th-lift-instances     , these >=0.8     , time   if impl(ghc >= 8.8)@@ -127,12 +127,12 @@     , pcre-light     , predicate-typed     , pretty-terminal >=0.1.0.0-    , random     , safe     , string-conversions     , template-haskell     , text     , th-lift+    , th-lift-instances     , these >=0.8     , time   if impl(ghc >= 8.8)@@ -172,7 +172,6 @@     , pcre-light     , predicate-typed     , pretty-terminal >=0.1.0.0-    , random     , safe     , stm     , string-conversions@@ -182,6 +181,7 @@     , template-haskell     , text     , th-lift+    , th-lift-instances     , these >=0.8     , time   if impl(ghc >= 8.8)
src/Predicate.hs view
@@ -14,4 +14,5 @@ import Predicate.Util_TH
 import Predicate.Prelude
 import Predicate.Refined
-import Predicate.TH_Orphans ()+import Predicate.TH_Orphans ()
+import Instances.TH.Lift ()
src/Predicate/Core.hs view
@@ -10,6 +10,7 @@ {-# LANGUAGE TypeFamilies #-}
 {-# LANGUAGE PolyKinds #-}
 {-# LANGUAGE ScopedTypeVariables #-}
+{-# LANGUAGE QuasiQuotes #-}
 {-# LANGUAGE OverloadedStrings #-}
 {-# LANGUAGE EmptyDataDeriving #-}
 {-# LANGUAGE NoStarIsType #-}
@@ -116,7 +117,6 @@ 
  -- ** miscellaneous
   , Swap
-
   ) where
 import Predicate.Misc
 import Predicate.Util
@@ -131,9 +131,11 @@ import Control.Monad (zipWithM)
 import Control.Arrow (right)
 import Data.List (find)
+import Data.Maybe (fromMaybe)
 import Data.Tree (Tree)
 import Data.Coerce (Coercible)
 import Data.Tree.Lens (root)
+import qualified Text.Regex.PCRE.Heavy as RH
 -- $setup
 -- >>> :set -XDataKinds
 -- >>> :set -XTypeApplications
@@ -1111,7 +1113,7 @@                     if anyOf (ttForest . folded . root . peValP) (has _FailP) qq
                     then qq & ttForest %~ (hh pp:) -- we still need pp for context
                     else e
-          Right q -> mkNodeCopy opts qq (lit3 opts msg0 q "" (topMessageEgregious qq)) [hh pp, hh qq]
+          Right q -> mkNodeCopy opts qq (lit3 opts msg0 q "" (topMessageEgregious (_ttString qq))) [hh pp, hh qq]
 
 -- | infixl version of 'Predicate.Core.>>'
 data p >>> q deriving Show
@@ -1132,11 +1134,15 @@   type PP (p << q) x = PP (LeftArrowsT p q) x
   eval _ = eval (Proxy @(LeftArrowsT p q))
 
--- bearbeiten! only used by >>
-topMessageEgregious :: TT a -> String
-topMessageEgregious pp = innermost (_ttString pp)
-  where innermost = ('{':) . reverse . ('}':) . takeWhile (/='{') . dropWhile (=='}') . reverse
+topMessageEgregious :: String -> String
+topMessageEgregious s =
+  let ret = fromMaybe "" $ (RH.scan topMessageExtractRe s ^? _last . _2 . _last)
+  in '{' : (if null ret then s else ret) <> "}"
 
+
+topMessageExtractRe :: RH.Regex
+topMessageExtractRe = [RH.re|^.*\{([^}]+)\}.*?|]
+
 -- | unwraps a value (see '_Wrapped'')
 --
 -- >>> pz @Unwrap (SG.Sum (-13))
@@ -1208,8 +1214,14 @@   type PP (Wrap t p) x = PP (WrapT t p) x
   eval _ = eval (Proxy @(WrapT t p))
 
-
 -- | used internally for type inference
+--
+-- >>> pz @(FromIntegral' (Proxy (SG.Sum _) >> UnproxyT) 23) ()
+-- Val (Sum {getSum = 23})
+--
+-- >>> pz @(FromIntegral' (Hole (SG.Sum _)) 23) () -- equivalent to Proxy UnproxyT above
+-- Val (Sum {getSum = 23})
+--
 data UnproxyT deriving Show
 
 instance Typeable t => P UnproxyT (Proxy (t :: Type)) where
@@ -1495,11 +1507,11 @@ data p <..> q deriving Show
 infix 4 <..>
 
-type BetweenT p q = Between p q Id
+type BetweenOpT p q = Between p q Id
 
-instance P (BetweenT p q) x => P (p <..> q) x where
-  type PP (p <..> q) x = PP (BetweenT p q) x
-  eval _ = evalBool (Proxy @(BetweenT p q))
+instance P (BetweenOpT p q) x => P (p <..> q) x where
+  type PP (p <..> q) x = PP (BetweenOpT p q) x
+  eval _ = evalBool (Proxy @(BetweenOpT p q))
 
 -- | similar to 'all'
 --
src/Predicate/Data/Char.hs view
@@ -19,8 +19,7 @@ -- | promoted character functions
 module Predicate.Data.Char (
  -- ** constructor
-    Char1
-  , C
+    C
 
  -- ** character predicates
   , IsLower
@@ -71,32 +70,19 @@ 
 -- | extracts the first character from a non empty 'GHC.TypeLits.Symbol'
 --
--- >>> pz @(Char1 "aBc") ()
+-- >>> pz @(C "aBc") ()
 -- Val 'a'
 --
-data Char1 (s :: Symbol) deriving Show
+data C (s :: Symbol) deriving Show
 instance ( KnownSymbol s
          , FailUnlessT (GL.CmpSymbol s "" DE.== 'GT)
-              ('GL.Text "Char1 symbol cannot be empty")
-         ) => P (Char1 s) a where
-  type PP (Char1 s) a = Char
+              ('GL.Text "C symbol cannot be empty")
+         ) => P (C s) a where
+  type PP (C s) a = Char
   eval _ opts _ =
      case symb @s of
-       [] -> errorInProgram "Char1: found empty Symbol/string"
-       c:_ -> pure $ mkNode opts (Val c) ("Char1 " <> showL opts c) []
-
-
--- | extracts the first character from a non empty 'GHC.TypeLits.Symbol': shorthand for 'Char1'
---
--- >>> pz @(C "aBc") ()
--- Val 'a'
---
-data C (s :: Symbol) deriving Show
-type CT s = Char1 s
-
-instance P (CT s) x => P (C s) x where
-  type PP (C s) x = PP (CT s) x
-  eval _ = eval (Proxy @(CT s))
+       [] -> errorInProgram "C: found empty Symbol/string"
+       c:_ -> pure $ mkNode opts (Val c) ("C " <> showL opts c) []
 
 
 -- | a predicate for determining if a character belongs to the given character set
src/Predicate/Data/Condition.hs view
@@ -314,7 +314,7 @@         msgbase0 = "Case(" <> show cpos <> " of " <> show (n-1) <> ")"
         msgbase1 = "Case(" <> show cpos <> ")"
         n = nat @n
-        pos = 1 + getLen @ps -- cos p1!
+        pos = 1 + getLen @ps
     rr <- eval (Proxy @r) opts z
     case getValueLR NoInline opts msgbase0 rr [] of
       Left e -> pure e
src/Predicate/Data/Either.hs view
@@ -194,11 +194,11 @@ -- >>> pz @(ShowP Id +++ Reverse) (Right "hello")
 -- Val (Right "olleh")
 --
--- >>> pl @(HeadDef 'False Id +++ Id) (Right @[Bool] 1) -- need @[Bool] cos we said 'False!
+-- >>> pl @(HeadDef 'False Id +++ Id) (Right @[Bool] 1) -- need @[Bool] to match with 'False
 -- Present Right 1 ((+++) Right 1 | 1)
 -- Val (Right 1)
 --
--- >>> pl @(HeadDef 'False Id +++ Id) (Left [True,False]) -- need @[Bool] cos we said 'False!
+-- >>> pl @(HeadDef 'False Id +++ Id) (Left [True,False]) -- need @[Bool] to match with 'False!
 -- Present Left True ((+++) Left True | [True,False])
 -- Val (Left True)
 --
@@ -214,7 +214,7 @@ -- Present Right 1 ((+++) Right 1 | 1)
 -- Val (Right 1)
 --
--- >>> pl @(HeadDef () Id +++ Id) (Right @[()] 1) -- this breaks! cos Left doesnt have a type
+-- >>> pl @(HeadDef () Id +++ Id) (Right @[()] 1) -- this breaks! as Left doesnt have a type
 -- Present Right 1 ((+++) Right 1 | 1)
 -- Val (Right 1)
 --
src/Predicate/Data/Extra.hs view
@@ -485,7 +485,7 @@          Right _ ->
           let xs = zipWith (*) (reverse x) (Safe.cycleNote msg0 [1,2])
               ys = map (\w -> if w>=10 then w-9 else w) xs
-              z = sum ys
+              z = sum' ys
               ret = z `mod` 10
           in if ret == 0 then mkNodeB opts True (msg0 <> " | " <> showL opts x) []
              else mkNodeB opts False (msg0 <> " map=" <> showL opts ys <> " sum=" <> showL opts z <> " ret=" <> showL opts ret <> showVerbose opts " | " x) []
src/Predicate/Data/Foldable.hs view
@@ -435,7 +435,7 @@ -- Present 52 ((>>) 52 | {getSum = 52})
 -- Val 52
 --
--- >>> pl @(FoldMap (SG.Max _) Id) [14 :: Int,8,17,13] -- cos Bounded!
+-- >>> pl @(FoldMap (SG.Max _) Id) [14 :: Int,8,17,13] -- allowed as the values are Bounded!
 -- Present 17 ((>>) 17 | {getMax = 17})
 -- Val 17
 --
@@ -444,7 +444,7 @@ -- Val True
 --
 -- >>> pl @((Len >> (Elem Id '[4,7,1] || (Mod Id 3 >> Same 0))) || (FoldMap (SG.Sum _) Id >> Gt 200)) [1..19]
--- False (False || False | ((>>) False | {1 == 0})}) || ((>>) False | {190 > 200}))
+-- False (False || False | ((>>) False | {1 == 0}) || ((>>) False | {190 > 200}))
 -- Val False
 --
 -- >>> pl @((Len >> (Elem Id '[4,7,1] || (Mod Id 3 >> Same 0))) || (FoldMap (SG.Sum _) Id >> Gt 200)) []
src/Predicate/Data/IO.hs view
@@ -43,28 +43,13 @@   , TimeUtc
   , TimeZt
 
-  -- ** random
-  , GenIO
-  , GenPure
-  , GenNext
-  , GenSplit
-  , GenRange
-  , RandomNext
-  , RandomList
-  , RandomRNext
-  , RandomRList
-
  ) where
 import Predicate.Core
 import Predicate.Misc
 import Predicate.Util
-import Predicate.Data.Enum (type (...))
 import Predicate.Data.Maybe (IsJust)
-import Predicate.Data.Iterator (Foldl)
-import Predicate.Data.List (type (:+))
-import Predicate.Data.Monoid (type (<>), MEmptyT)
+import Predicate.Data.Monoid (type (<>))
 import Predicate.Data.ReadShow (ReadP)
-import Predicate.Data.Tuple (Second)
 import GHC.TypeLits (Symbol,KnownSymbol)
 import Data.Proxy (Proxy(Proxy))
 import qualified Control.Exception as E
@@ -75,7 +60,6 @@ import System.IO (hPutStr, withFile, IOMode(WriteMode, AppendMode))
 import System.Environment (getEnvironment, lookupEnv)
 import qualified Data.ByteString.Char8 as BS8
-import System.Random
 -- $setup
 -- >>> :set -XDataKinds
 -- >>> :set -XTypeApplications
@@ -358,160 +342,4 @@       Nothing -> mkNode opts (Fail (msg0 <> " must run in IO")) "" []
       Just (Left e) -> mkNode opts (Fail $ msg0 <> ":" <> e) "" []
       Just (Right ss) -> mkNode opts (Val ss) (msg0 <> "[" <> litVerbose opts "" ss <> "]") []
-
--- | generate a random number: see 'System.Random.newStdGen'
-data GenIO deriving Show
-
-instance P GenIO x where
-  type PP GenIO x = StdGen
-  eval _ opts _ = do
-    let msg0 = "GenIO"
-    mg <- runIO newStdGen
-    pure $ case mg of
-      Nothing -> mkNode opts (Fail (msg0 <> " must run in IO")) "" []
-      Just g -> mkNode opts (Val g) (msg0 <> "[" <> showVerbose opts "" g <> "]") []
-
--- | similar to 'System.Random.mkStdGen'
---
--- >>> pz @(GenPure Id) 1234
--- Val 1235 1
---
-data GenPure p deriving Show
-
-instance (PP p x ~ Int, P p x) => P (GenPure p) x where
-  type PP (GenPure p) x = StdGen
-  eval _ opts x = do
-    let msg0 = "GenPure"
-    pp <- eval (Proxy @p) opts x
-    pure $ case getValueLR NoInline opts msg0 pp [] of
-      Left e -> e
-      Right p ->
-        let g = mkStdGen p
-        in mkNode opts (Val g) msg0 [hh pp]
-
--- | get the next random number of type @t@ using generator @r@ : similar to 'System.Random.random'
---
--- >>> pz @(UnfoldN 5 (RandomNext Bool Id) Id) (mkStdGen 3)
--- Val [True,True,False,True,True]
---
-data RandomNext (t :: Type) p deriving Show
-
-instance ( Random t
-         , P p x
-         , Show (PP p x)
-         , RandomGen (PP p x)
-         ) => P (RandomNext t p) x where
-  type PP (RandomNext t p) x = (t, PP p x)
-  eval _ opts x = do
-    let msg0 = "RandomNext"
-    pp <- eval (Proxy @p) opts x
-    pure $ case getValueLR NoInline opts msg0 pp [] of
-      Left e -> e
-      Right p ->
-        let (a,g) = random p
-        in mkNode opts (Val (a,g)) (msg0 <> "[" <> showVerbose opts "" g <> "]") [hh pp]
-
--- | get a list of @n@ random numbers of type @t@ using generator @p@: similar to 'System.Random.randoms'
---
--- >>> pz @(RandomList 10 Bool Id) (mkStdGen 4)
--- Val ([True,True,False,True,True,True,True,False,False,True],2036574526 1336516156)
---
-data RandomList n (t :: Type) p deriving Show
-type RandomListT n t p = Foldl (Fst >> Second (RandomNext t Id) >> '(L21 :+ Fst, L22)) '(MEmptyT [t],p) (1...n)
-
-instance P (RandomListT n t p) x => P (RandomList n t p) x where
-  type PP (RandomList n t p) x = PP (RandomListT n t p) x
-  eval _ = eval (Proxy @(RandomListT n t p))
-
-
--- | get the next random number of type @t@ in range between @p@ and @q@ using generator @r@ : similar to 'System.Random.randomR'
---
--- >>> pz @(Foldl (Fst >> Second (RandomRNext Int 1 100 Id) >> '(L21 :+ Fst, L22)) '( MEmptyT [Int] ,Id) (1...5)) (mkStdGen 3)
--- Val ([12,26,33,94,64],781515869 652912057)
---
--- >>> pz @(UnfoldN 10 (RandomRNext _ (C "A") (C "H") Id) Id) (mkStdGen 3)
--- Val "DBABDDEEEA"
---
-data RandomRNext (t :: Type) p q r deriving Show
-
-instance ( Random t
-         , P r x
-         , RandomGen (PP r x)
-         , Show (PP r x)
-         , PP p x ~ t
-         , PP q x ~ t
-         , P p x
-         , P q x
-         ) => P (RandomRNext t p q r) x where
-  type PP (RandomRNext t p q r) x = (t, PP r x)
-  eval _ opts x = do
-    let msg0 = "RandomRNext"
-    lr <- runPQ NoInline msg0 (Proxy @p) (Proxy @q) opts x []
-    case lr of
-      Left e -> pure e
-      Right (p,q,pp,qq) -> do
-        rr <- eval (Proxy @r) opts x
-        pure $ case getValueLR NoInline opts msg0 rr [hh pp,hh qq] of
-          Left e -> e
-          Right r ->
-            let (a,g) = randomR (p,q) r
-            in mkNode opts (Val (a,g)) (msg0 <> "[" <> showVerbose opts "" g <> "]") [hh pp, hh qq, hh rr]
-
--- | list @n@ random numbers of type @t@ in range between @p@ and @q@ using generator @r@ : similar to 'System.Random.randomRs'
---
--- >>> pz @(RandomRList 10 Int 0 6 Id) (mkStdGen 1)
--- Val ([6,6,5,1,3,0,3,6,5,2],1244126523 1336516156)
---
--- >>> pz @(RandomRList 10 _ (C "A") (C "F") Id) (mkStdGen 1)
--- Val ("EEBCBEFBEF",1244126523 1336516156)
---
-data RandomRList n (t :: Type) p q r deriving Show
-type RandomRListT n t p q r = Foldl (Fst >> Second (RandomRNext t p q Id) >> '(L21 :+ Fst, L22)) '(MEmptyT [t],r) (1...n)
-
-instance P (RandomRListT n t p q r) x => P (RandomRList n t p q r) x where
-  type PP (RandomRList n t p q r) x = PP (RandomRListT n t p q r) x
-  eval _ = eval (Proxy @(RandomRListT n t p q r))
-
--- | similar to 'System.Random.split'
-data GenSplit p deriving Show
-
-instance (RandomGen (PP p x), P p x) => P (GenSplit p) x where
-  type PP (GenSplit p) x = (PP p x, PP p x)
-  eval _ opts x = do
-    let msg0 = "GenSplit"
-    pp <- eval (Proxy @p) opts x
-    pure $ case getValueLR NoInline opts msg0 pp [] of
-      Left e -> e
-      Right p ->
-        let g = split p
-        in mkNode opts (Val g) msg0 [hh pp]
-
-
--- | similar to 'System.Random.next'
-data GenNext p deriving Show
-
-instance (RandomGen (PP p x), P p x) => P (GenNext p) x where
-  type PP (GenNext p) x = (Int, PP p x)
-  eval _ opts x = do
-    let msg0 = "GenNext"
-    pp <- eval (Proxy @p) opts x
-    pure $ case getValueLR NoInline opts msg0 pp [] of
-      Left e -> e
-      Right p ->
-        let g = next p
-        in mkNode opts (Val g) msg0 [hh pp]
-
--- | similar to 'System.Random.genRange'
-data GenRange p deriving Show
-
-instance (RandomGen (PP p x), P p x) => P (GenRange p) x where
-  type PP (GenRange p) x = (Int, Int)
-  eval _ opts x = do
-    let msg0 = "GenRange"
-    pp <- eval (Proxy @p) opts x
-    pure $ case getValueLR NoInline opts msg0 pp [] of
-      Left e -> e
-      Right p ->
-        let g = genRange p
-        in mkNode opts (Val g) msg0 [hh pp]
 
src/Predicate/Data/Index.hs view
@@ -133,7 +133,7 @@   type PP (LookupFail msg v w) x = PP (LookupFailT msg v w) x
   eval _ = eval (Proxy @(LookupFailT msg v w))
 
--- | similar to 'Data.List.!!' using an 'Ixed' container
+-- | similar to 'Data.List.!!' for lists
 --
 -- >>> pz @(Ix 4 "not found") ["abc","D","eF","","G"]
 -- Val "G"
@@ -226,6 +226,7 @@              Right _ -> mkNodeCopy opts pp msg1 [hh pp]
          Just a -> pure $ mkNode opts (Val a) (msg0 <> " " <> showL opts a) []
 
+-- | similar to 'Data.List.!!' for lists with a default error message on failure
 data Ix' (n :: Nat) deriving Show
 type IxT' (n :: Nat) = Ix n (FailP "Ix index not found")
 
src/Predicate/Data/Iterator.hs view
@@ -354,11 +354,6 @@   UnfoldrT (Maybe (b, _s)) = b
 
 -- | run @p@ @n@ times with state @s@
---
--- >>> :m + System.Random
--- >>> pz @(UnfoldN 10 (RandomRNext Int 1 100 Id) Id) (mkStdGen 3)
--- Val [64,94,33,26,12,8,81,41,21,89]
---
 data UnfoldN n p s deriving Show
 
 -- have to rewrite (a,s) to (a,(s,n)) hence the L11 ...
@@ -519,7 +514,7 @@          msgbase0 = "Para(" <> show cpos <> " of " <> show (n-1) <> ")"
          msgbase1 = "Para(" <> show cpos <> ")"
          n = nat @n
-         pos = 1 + getLen @ps -- cos p1!
+         pos = 1 + getLen @ps
      pp <- eval (Proxy @p) opts a
      case getValueLR NoInline opts msgbase0 pp [] of
        Left e -> pure e
src/Predicate/Data/Lifted.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE TypeOperators #-}
+{-# LANGUAGE LambdaCase #-}
 {-# LANGUAGE TupleSections #-}
 {-# LANGUAGE UndecidableInstances #-}
 {-# LANGUAGE FlexibleContexts #-}
@@ -95,7 +96,6 @@ -- >>> :m + Data.Ratio
 -- >>> :m + Control.Lens
 -- >>> :m + Control.Lens.Action
--- >>> :m + System.Random
 
 -- | similar to 'Control.Applicative.<$'
 --
@@ -350,15 +350,6 @@ -- >>> pz @('True $& 4 $& Id $$ "aa") (,,)
 -- Val (4,True,"aa")
 --
--- >>> pz @(Id $$ '(100,120)) (flip randomR (mkStdGen 7))
--- Val (114,320112 40692)
---
--- >>> pz @(Id $$ GenPure 12) (randomR ('a','f'))
--- Val ('f',520182 40692)
---
--- >>> pz @(Id $$ GenIO) (randomR ('a','f')) ^!? acts . _Val . _1 . nearly 'a' (`elem` ['a'..'f'])
--- Just ()
---
 -- >>> pz @((Id $$ "abc" $$ Wrap (SG.Sum _) 14) >> Id <> Id) These
 -- Val (These "abcabc" (Sum {getSum = 28}))
 --
@@ -1298,7 +1289,7 @@                     & ttForest %~ (hhs <>)
                     & ttString %~ (msg0 <>) . (ind <>) . nullIf " "
 
-
+-- | adt for testing out possible outcomes of Bifoldable used in BiMap
 data ELR a b = EEmpty | ELeft !a | ERight !b | EBoth !a !b deriving (Show,Eq,Ord,Foldable,Functor,Traversable)
 
 instance Bifunctor ELR where
@@ -1324,3 +1315,11 @@       ELeft a -> ELeft <$> f a
       ERight b -> ERight <$> g b
       EBoth a b -> EBoth <$> f a <*> g b
+
+instance SwapC ELR where
+  swapC =
+    \case
+      EEmpty -> EEmpty
+      ELeft a -> ERight a
+      ERight b -> ELeft b
+      EBoth a b -> EBoth b a
src/Predicate/Data/List.hs view
@@ -104,7 +104,7 @@ import Predicate.Data.Numeric (Mod)
 import Predicate.Data.Monoid (type (<>))
 import Control.Lens
-import Data.List (partition, intercalate, inits, tails, unfoldr, isInfixOf, isPrefixOf, isSuffixOf, sortOn)
+import Data.List (foldl', partition, intercalate, inits, tails, unfoldr, sortOn)
 import Data.Proxy (Proxy(Proxy))
 import Control.Monad (zipWithM)
 import Data.Kind (Type)
@@ -1558,7 +1558,7 @@   type PP Reverse x = x
   eval _ opts as =
     let msg0 = "Reverse"
-        d = reverse as
+        d = foldl' (flip (:)) [] as
     in pure $ mkNode opts (Val d) (show3 opts msg0 d as) []
 
 -- | reverses using 'reversing'
@@ -1948,7 +1948,7 @@   type PP Sum x = ExtractAFromTA x
   eval _ opts as =
     let msg0 = "Sum"
-        v = sum as
+        v = sum' as
     in pure $ mkNode opts (Val v) (show3 opts msg0 v as) []
 
 -- | similar to 'Data.List.product'
@@ -1968,7 +1968,7 @@   type PP Product x = ExtractAFromTA x
   eval _ opts as =
     let msg0 = "Product"
-        v = product as
+        v = product' as
     in pure $ mkNode opts (Val v) (show3 opts msg0 v as) []
 
 -- | similar to 'Data.List.minimum'
@@ -1990,9 +1990,9 @@     let msg0 = "Min"
     pure $ case as' of
      [] -> mkNode opts (Fail "empty list") msg0 []
-     as@(_:_) ->
-       let v = minimum as
-       in mkNode opts (Val v) (show3 opts msg0 v as) []
+     xs@(a:as) ->
+       let v = foldl' min a as
+       in mkNode opts (Val v) (show3 opts msg0 v xs) []
 
 -- | similar to 'Data.List.maximum'
 --
@@ -2013,9 +2013,9 @@     let msg0 = "Max"
     pure $ case as' of
       [] -> mkNode opts (Fail "empty list") msg0 []
-      as@(_:_) ->
-        let v = maximum as
-        in mkNode opts (Val v) (show3 opts msg0 v as) []
+      xs@(a:as) ->
+        let v = foldl' max a as
+        in mkNode opts (Val v) (show3 opts msg0 v xs) []
 
 data IsFixImpl (cmp :: Ordering) p q deriving Show
 
@@ -2030,10 +2030,7 @@   type PP (IsFixImpl cmp p q) x = Bool
   eval _ opts x = do
     let cmp = getOrdering @cmp
-        (ff,msg0) = case cmp of
-                    LT -> (isPrefixOf, "IsPrefix")
-                    EQ -> (isInfixOf, "IsInfix")
-                    GT -> (isSuffixOf, "IsSuffix")
+        (ff,msg0) = cmpOf cmp
     lr <- runPQ NoInline msg0 (Proxy @p) (Proxy @q) opts x []
     pure $ case lr of
       Left e -> e
src/Predicate/Data/Numeric.hs view
@@ -72,15 +72,15 @@ import Predicate.Util
 import Predicate.Data.Ordering (type (==))
 import GHC.TypeLits (Nat,KnownNat)
-import qualified GHC.TypeLits as GL
-import Data.List (elemIndex, unfoldr)
+import Data.List (elemIndex)
+import Data.Function (fix)
 import Data.Typeable (Typeable, Proxy(Proxy))
 import Data.Kind (Type)
 import qualified Numeric
 import Data.Char (toLower)
 import Data.Ratio ((%))
 import GHC.Real (Ratio((:%)))
-import qualified Safe (fromJustNote)
+import qualified Safe (fromJustNote, atNote)
 -- $setup
 -- >>> :set -XDataKinds
 -- >>> :set -XTypeApplications
@@ -91,6 +91,7 @@ -- >>> import qualified Data.Semigroup as SG
 -- >>> import Data.Time
 
+-- | 'fromInteger' function where you need to provide a reference to the type @t@ of the result
 data FromInteger' t n deriving Show
 
 instance ( Num (PP t a)
@@ -143,6 +144,7 @@   type PP (FromInteger t) x = PP (FromIntegerT t) x
   eval _ = eval (Proxy @(FromIntegerT t))
 
+-- | 'fromIntegral' function where you need to provide a reference to the type @t@ of the result
 data FromIntegral' t n deriving Show
 
 instance ( Num (PP t a)
@@ -215,7 +217,7 @@         let r = toRational a
         in mkNode opts (Val r) (show3 opts msg0 r a) [hh pp]
 
--- | 'fromRational' function where you need to provide the type @t@ of the result
+-- | 'fromRational' function where you need to provide a reference to the type @t@ of the result
 --
 -- >>> pl @(FromRational' Fst Snd) (1,2 % 5)
 -- Present 0.4 (FromRational 0.4 | 2 % 5)
@@ -254,7 +256,7 @@   type PP (FromRational t) x = PP (FromRationalT t) x
   eval _ = eval (Proxy @(FromRationalT t))
 
--- | 'truncate' function where you need to provide the type @t@ of the result
+-- | 'truncate' function where you need to provide a reference to the type @t@ of the result
 --
 -- >>> pl @(Truncate' (Fst >> UnproxyT) Snd) (Proxy @Integer,2.3)
 -- Present 2 (Truncate 2 | 2.3)
@@ -294,7 +296,7 @@   type PP (Truncate t) x = PP (TruncateT t) x
   eval _ = eval (Proxy @(TruncateT t))
 
--- | 'ceiling' function where you need to provide the type @t@ of the result
+-- | 'ceiling' function where you need to provide a reference to the type @t@ of the result
 data Ceiling' t p deriving Show
 
 instance ( P p x
@@ -325,7 +327,7 @@   type PP (Ceiling t) x = PP (CeilingT t) x
   eval _ = eval (Proxy @(CeilingT t))
 
--- | 'floor' function where you need to provide the type @t@ of the result
+-- | 'floor' function where you need to provide a reference to the type @t@ of the result
 data Floor' t p deriving Show
 
 instance ( P p x
@@ -951,10 +953,11 @@         in mkNode opts (Val d) (show3 opts msg0 d p) [hh pp]
 
 -- supports negative numbers unlike readInt
+-- | Read a number using base 2 through a maximum of 36 with @t@ a reference to a type
 data ReadBase' t (n :: Nat) p deriving Show
 
 instance ( Typeable (PP t x)
-         , ZwischenT 2 36 n
+         , BetweenT "ReadBase'" 2 36 n
          , Show (PP t x)
          , Num (PP t x)
          , KnownNat n
@@ -1070,8 +1073,7 @@ --
 data ShowBase (n :: Nat) deriving Show
 
-instance ( 2 GL.<= n
-         , n GL.<= 36
+instance ( BetweenT "ShowBase" 2 36 n
          , KnownNat n
          , Integral x
          ) => P (ShowBase n) x where
@@ -1083,7 +1085,7 @@         p :: Integer
         p = fromIntegral x
         (ff,a') = if p < 0 then (('-':), abs p) else (id,p)
-        b = Numeric.showIntAtBase (fromIntegral n) (xs !!) a' ""
+        b = Numeric.showIntAtBase (fromIntegral n) (Safe.atNote "ShowBase out of range" xs) a' ""
     in pure $ mkNode opts (Val (ff b)) (msg0 <> " " <> litL opts (ff b) <> showVerbose opts " | " p) []
 
 -- | Display a number at base >= 2 but just show as a list of ints: ignores the sign
@@ -1110,7 +1112,7 @@       Right (fromIntegral -> n,fromIntegral -> p,nn,pp) ->
          let hhs = [hh nn, hh pp]
          in if n < 2 then mkNode opts (Fail (msg0 <> " base must be greater than 1")) "" hhs
-            else let xs = reverse $ unfoldr (\s -> if s<1 then Nothing else Just (swapC (divMod s n))) (abs p)
+            else let xs = fix (\f s -> if s<1 then id else let (a,b) = divMod s n in f a . (b:)) (abs p) []
                  in mkNode opts (Val xs) (msg0 <> showVerbose opts " | " n <> showVerbose opts " | " p) hhs
 
 -- | convert to bits
src/Predicate/Data/Proxy.hs view
@@ -37,7 +37,7 @@ import Predicate.Util
 import qualified GHC.TypeLits as GL
 import Data.Kind (Type)
-import Data.Typeable
+import Data.Typeable (Proxy(..))
 -- $setup
 -- >>> :set -XDataKinds
 -- >>> :set -XTypeApplications
@@ -48,7 +48,7 @@ -- >>> import qualified Data.Semigroup as SG
 -- >>> :m + Text.Show.Functions
 -- >>> :m + Data.Ratio
-
+-- >>> :m + Data.Typeable
 
 -- | makes a proxy from a simple type: similar to the P instance for 'Proxy but requires a show instance
 --
src/Predicate/Data/Regex.hs view
@@ -198,7 +198,7 @@              Right regex ->
                case splitAt (oRecursion opts) $ RH.scan regex q of
                  (b, _:_) -> mkNode opts (Fail ("Regex looping(" ++ show (oRecursion opts) ++ ")")) (msg1 <> " " <> show (take 10 b) <> "..." <> showVerbose opts " | " q) hhs
-                 ([], _) -> -- this is a failure cos empty string returned: so reuse p?
+                 ([], _) -> -- this is a failure because an empty string is returned: so reuse p?
                              mkNode opts (Fail "Regex no results") (msg1 <> showVerbose opts " | " q) [hh pp, hh qq]
                  (b, _) -> mkNode opts (Val b) (lit3 opts msg1 b "" q) [hh pp, hh qq]
 
@@ -289,7 +289,7 @@           Right regex ->
             case splitAt (oRecursion opts) $ RH.scanRanges regex q of
               (b, _:_) -> mkNode opts (Fail ("Regex looping(" ++ show (oRecursion opts) ++ ")")) (msg1 <> " " <> show (take 10 b) <> "..." <> showVerbose opts " | " q) hhs
-              ([], _) -> -- this is a failure cos empty string returned: so reuse p?
+              ([], _) -> -- this is a failure because an empty string is returned: so reuse p?
                          mkNode opts (Fail "Regex no results") (msg1 <> showVerbose opts " | " q) hhs
               (b, _) -> mkNode opts (Val b) (lit3 opts msg1 b "" q) hhs
 
@@ -337,7 +337,7 @@           Right regex ->
             case splitAt (oRecursion opts) $ RH.split regex q of
               (b, _:_) -> mkNode opts (Fail ("Regex looping(" ++ show (oRecursion opts) ++ ")")) (msg1 <> " " <> show (take 10 b) <> "..." <> showVerbose opts " | " q) hhs
-              ([], _) -> -- this is a failure cos empty string returned: so reuse p?
+              ([], _) -> -- this is a failure because an empty string is returned: so reuse p?
                          mkNode opts (Fail "Regex no results") (msg1 <> showVerbose opts " | " q) hhs
               (b, _) -> mkNode opts (Val b) (lit3 opts msg1 b "" q) hhs
 
src/Predicate/Data/String.hs view
@@ -39,7 +39,7 @@ import Predicate.Util
 import qualified GHC.TypeLits as GL
 import Control.Lens
-import Data.List (dropWhileEnd, isInfixOf, isPrefixOf, isSuffixOf)
+import Data.List (dropWhileEnd)
 import qualified Data.Text.Lens as DTL
 import Data.Proxy (Proxy(Proxy))
 import Data.Kind (Type)
@@ -50,7 +50,7 @@ import qualified Data.ByteString.Lazy.Char8 as BL8
 import qualified Data.Text as T
 import qualified Data.Text.Lazy as TL
-
+import Control.Arrow (second)
 -- $setup
 -- >>> :set -XDataKinds
 -- >>> :set -XTypeApplications
@@ -207,11 +207,7 @@     let cmp = getOrdering @cmp
         ignore = getBool @ignore
         lwr = if ignore then map toLower else id
-        (ff,msg0) = case cmp of
-                    LT -> (isPrefixOf, "IsPrefixC")
-                    EQ -> (isInfixOf, "IsInfixC")
-                    GT -> (isSuffixOf, "IsSuffixC")
-
+        (ff,msg0) = second (<>"C") $ cmpOf cmp
     lr <- runPQ NoInline msg0 (Proxy @p) (Proxy @q) opts x []
     pure $ case lr of
       Left e -> e
@@ -340,23 +336,23 @@ instance ToStringC BS8.ByteString where
   toStringC = BS8.unpack
 
--- | 'fromString' function where you need to provide the type @t@ of the result
-data FromString' t s deriving Show
+-- | 'fromString' function where you need to provide a reference to the type @t@ of the result
+data FromString' t p deriving Show
 
-instance ( P s a
-         , PP s a ~ String
+instance ( P p a
+         , PP p a ~ String
          , Show (PP t a)
          , IsString (PP t a)
-         ) => P (FromString' t s) a where
-  type PP (FromString' t s) a = PP t a
+         ) => P (FromString' t p) a where
+  type PP (FromString' t p) a = PP t a
   eval _ opts a = do
     let msg0 = "FromString"
-    ss <- eval (Proxy @s) opts a
-    pure $ case getValueLR NoInline opts msg0 ss [] of
+    pp <- eval (Proxy @p) opts a
+    pure $ case getValueLR NoInline opts msg0 pp [] of
       Left e -> e
-      Right s ->
-        let b = fromString @(PP t a) s
-        in mkNode opts (Val b) (msg0 <> " " <> showL opts b) [hh ss]
+      Right p ->
+        let b = fromString @(PP t a) p
+        in mkNode opts (Val b) (msg0 <> " " <> showL opts b) [hh pp]
 
 -- | 'fromString' function where you need to provide the type @t@ of the result
 --
src/Predicate/Data/These.hs view
@@ -340,7 +340,7 @@ data IsTh (th :: These x y) deriving Show
 -- x y can be anything
 
--- trying to avoid Show instance cos of ambiguities
+-- trying to avoid Show instance because more likely to have ambiguity errors
 instance ( x ~ These a b
          , Show a
          , Show b
src/Predicate/Data/Tuple.hs view
@@ -356,6 +356,9 @@ -- Present (1999-01-01,2001-02-12) (Both)
 -- Val (1999-01-01,2001-02-12)
 --
+-- >>> pz @(Both (Id * Id) >> ((Fst + Snd) ** (DivI Double 1 2))) (3,4)
+-- Val 5.0
+--
 data Both p deriving Show
 instance ( P p a
          , P p a'
@@ -373,14 +376,21 @@           Right b' ->
             mkNode opts (Val (b,b')) msg0 [hh pp, hh pp']
 
--- | similar to 'Data.Function.on'
+-- | similar to 'Data.Function.on': may require kind signatures: Both is a better choice
 --
 -- >>> pz @('(4,2) >> On (**) (FromIntegral _)) ()
 -- Val 16.0
 --
+-- >>> pz @('(4,2) >> Both (FromIntegral _) >> Fst ** Snd) () -- equivalent to the above but easier on ghc
+-- Val 16.0
+--
 -- >>> pz @(On (+) (Id * Id) >> Id ** (1 % 2 >> FromRational _)) (3,4)
 -- Val 5.0
 --
+-- >>> pz @(Both (Id * Id) >> ((Fst + Snd) ** (1 % 2 >> FromRational _))) (3,4) -- equivalent to the above but easier on ghc
+-- Val 5.0
+--
+
 data On (p :: Type -> Type -> k2) q deriving Show
 
 instance ( P q a
@@ -403,7 +413,7 @@               Left e -> e
               Right p -> mkNode opts (Val p) msg0 [hh qq, hh qq', hh pp]
 
--- | create a n tuple from a list
+-- | create a @n@ tuple from a list or fail
 --
 -- >>> pz @(Tuple 4) "abcdefg"
 -- Val ('a','b','c','d')
@@ -435,7 +445,7 @@          Left es -> mkNode opts (Fail (msg0 <> " not enough elements(" <> show (length as) <> ")")) (showVerbose opts " | " es) []
          Right r -> mkNode opts (Val r) msg0 []
 
--- | create a n tuple from a list
+-- | create a @n@ tuple from a list and return as an Either
 --
 -- >>> pz @(Tuple' 4) "abcdefg"
 -- Val (Right ('a','b','c','d'))
src/Predicate/Misc.hs view
@@ -49,7 +49,7 @@   , JoinT
   , FailWhenT
   , FailUnlessT
-  , ZwischenT
+  , BetweenT
 
  -- ** extract values from the type level
   , GetBool(..)
@@ -125,7 +125,9 @@   , asProxyRight
   , removeAnsi
   , _Id
-
+  , sum'
+  , product'
+  , cmpOf
   ) where
 import qualified GHC.TypeNats as GN
 import GHC.TypeLits (Symbol,Nat,KnownSymbol,KnownNat,ErrorMessage((:$$:),(:<>:)))
@@ -149,7 +151,7 @@ import GHC.Stack (HasCallStack)
 import Data.Containers.ListUtils (nubOrd)
 import Control.Arrow (Arrow((***)),ArrowChoice(left))
-import Data.List (intercalate, unfoldr)
+import Data.List (foldl', intercalate, unfoldr, isPrefixOf, isInfixOf, isSuffixOf)
 import qualified Safe (headNote)
 import Data.Char (isSpace)
 import qualified Control.Exception as E
@@ -163,15 +165,17 @@ -- >>> :set -XTypeOperators
 
 -- | type level Between
-type family ZwischenT (a :: Nat) (b :: Nat) (v :: Nat) :: Constraint where
-  ZwischenT m n v =
+type family BetweenT (s :: Symbol) (a :: Nat) (b :: Nat) (v :: Nat) :: Constraint where
+  BetweenT s m n v =
      FailUnlessT (AndT (m GL.<=? v) (v GL.<=? n))
-            ('GL.Text "ZwischenT failure"
+            ('GL.Text s
+             ':<>: 'GL.Text " failed"
              ':$$: 'GL.ShowType v
-             ':$$: 'GL.Text " is outside of "
-             ':$$: 'GL.ShowType m
-             ':<>: 'GL.Text " and "
-             ':<>: 'GL.ShowType n)
+             ':<>: 'GL.Text " is outside the range ["
+             ':<>: 'GL.ShowType m
+             ':<>: 'GL.Text ".."
+             ':<>: 'GL.ShowType n
+             ':<>: 'GL.Text "]")
 
 -- | helper method that fails with a msg when True
 type family FailWhenT (b :: Bool) (msg :: GL.ErrorMessage) :: Constraint where
@@ -1188,7 +1192,6 @@ 
 pureTryTest :: a -> IO (Either () a)
 pureTryTest = fmap (left (const ())) . E.try @E.SomeException . E.evaluate
---pureTryTest = over (mapped . _Left) (const ()) . E.try @E.SomeException . E.evaluate
 
 pureTryTestPred :: (String -> Bool)
                 -> a
@@ -1267,3 +1270,14 @@ instance SwapC ((,,,,,,) a b c d e) where
   swapC (a,b,c,d,e,f,g) = (a,b,c,d,e,g,f)
 
+sum' :: (Foldable t, Num a) => t a -> a
+sum' = foldl' (+) 0
+
+product' :: (Foldable t, Num a) => t a -> a
+product' = foldl' (*) 1
+
+cmpOf :: Eq a => Ordering -> ([a] -> [a] -> Bool, String)
+cmpOf = \case
+           LT -> (isPrefixOf, "IsPrefix")
+           EQ -> (isInfixOf, "IsInfix")
+           GT -> (isSuffixOf, "IsSuffix")
src/Predicate/TH_Orphans.hs view
@@ -9,8 +9,7 @@ import Data.Time
 import Data.Fixed (Fixed(..))
 import qualified Language.Haskell.TH.Lift as TL
-import System.Random
-import Data.Proxy
+import Data.Proxy (Proxy)
 
 deriving instance Lift Day
 deriving instance Lift LocalTime
@@ -22,8 +21,6 @@ $(TL.deriveLift ''DiffTime)
 
 deriving instance Lift UTCTime
-
-$(TL.deriveLift ''StdGen)
 
 $(TL.deriveLift ''Proxy)
 
src/Predicate/Util.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE DerivingStrategies #-}
+{-# LANGUAGE DeriveLift #-}
 {-# LANGUAGE GeneralizedNewtypeDeriving #-}
 {-# LANGUAGE TypeOperators #-}
 {-# LANGUAGE UndecidableInstances #-}
@@ -162,6 +163,8 @@ import Control.Monad (ap)
 import Data.Bool (bool)
 import GHC.Generics (Generic, Generic1)
+import qualified Language.Haskell.TH.Lift as TH
+import Instances.TH.Lift ()
 -- $setup
 -- >>> :set -XDataKinds
 -- >>> :set -XTypeApplications
@@ -175,6 +178,7 @@   | TrueP        -- ^ True predicate
   | ValP     -- ^ Any value
   deriving stock (Show, Ord, Eq, Read, Generic)
+  deriving TH.Lift
 
 makePrisms ''ValP
 
@@ -182,6 +186,7 @@ data PE = PE { _peValP :: !ValP -- ^ holds the result of running the predicate
              , _peString :: !String -- ^ optional strings to include in the results
              } deriving stock (Show, Read, Eq, Generic)
+               deriving TH.Lift
 
 makeLenses ''PE
 
@@ -245,6 +250,7 @@ -- | contains the typed result from evaluating an expression
 data Val a = Fail !String | Val !a
   deriving stock (Show, Eq, Ord, Read, Functor, Foldable, Traversable, Generic, Generic1)
+  deriving TH.Lift
 
 makePrisms ''Val
 
@@ -322,7 +328,9 @@                , _ttString :: !String  -- ^ detailed information eg input and output and text
                , _ttForest :: !(Forest PE) -- ^ the child nodes
                } deriving stock (Functor, Read, Show, Eq, Foldable, Traversable, Generic, Generic1)
+                 deriving TH.Lift
 
+-- dont expose lenses for _ttValP and _ttVal as they must be kept in sync: see ttVal
 makeLensesFor [("_ttString","ttString"),("_ttForest","ttForest")] ''TT
 
 instance Semigroup (TT a) where
@@ -377,16 +385,16 @@           in TT bp bt ss zs
       _ -> TT bp bt ss hs
 
--- | check that 'ValP' value is consistent with 'Val' a
+-- | check that the 'ValP' value is consistent with 'Val'
 validateValP :: ValP -> Val a -> ValP
 validateValP bp bt =
   case bt of
     Val _a -> case bp of
-                     FailP e -> errorInProgram $ "validateValP: found FailP for Val in Val e=" ++ e
+                     FailP e -> errorInProgram $ "validateValP: found Val and FailP e=" ++ e
                      _ -> bp
     Fail e -> case bp of
                 FailP e1 | e==e1 -> bp
-                         | otherwise -> errorInProgram $ "validateValP: found Fail but message mismatch in ValP " ++ show (e,e1)
+                         | otherwise -> errorInProgram $ "validateValP: found Fail and FailP but message mismatch in FailP " ++ show (e,e1)
                 _ -> errorInProgram $ "validateValP: found " ++ show bp ++ " expected FailP e=" ++ e
 
 -- | fix the 'ValP' value for the Bool case: ie use 'TrueP' and 'FalseP'
@@ -682,8 +690,8 @@ 
 litL' :: Int -> String -> String
 litL' i s =
-  let z = take i s
-  in z ++ if length z >= i then "..." else ""
+  let (z,e) = splitAt i s
+  in z ++ if null e then "" else "..."
 
 litBL :: POpts -> BL8.ByteString -> String
 litBL o s =
@@ -1251,7 +1259,7 @@               Val True -> TrueP
               Val False -> FalseP
 
--- | lens that keeps ValP in sync with Val for TT Bool
+-- | lens that keeps 'ValP' in sync with 'Val' for TT Bool
 --
 -- >>> (TT ValP (Val True) "xxx" [] & ttValBool %~ \b -> fmap not b) == TT FalseP (Val False) "xxx" []
 -- True
@@ -1272,7 +1280,7 @@                Val True -> TrueP
                Val False -> FalseP
 
--- | lens from TT to Val that also keeps ValP in sync with Val
+-- | lens from 'TT' to 'Val' that also keeps 'ValP' in sync with 'Val'
 --
 -- >>> (TT FalseP (Val True) "xxx" [] & ttVal %~ id) == TT ValP (Val True) "xxx" []
 -- True
test/TestPredicate.hs view
@@ -91,7 +91,7 @@   , expectEQR (Just ()) (pz @(Proxy GE.Any) () ^!? acts . _Val . only (Proxy @_))
   , expectEQR (Just ()) (pz @(Proxy _) () ^!? acts . _Val . only (Proxy @GE.Any))
 
-  , expectBT (Val (111,'b')) $ pl @('(123,Char1 "c") >> (Id - 12 *** Pred)) ()
+  , expectBT (Val (111,'b')) $ pl @('(123,C "c") >> (Id - 12 *** Pred)) ()
   , expectBT (Fail "'Nothing found Just") $ pl @'Nothing (Just 12)
 
   , expectBT (Val [Just 1,Just 2,Just 3,Just 4]) $ pl @Sequence (Just [1..4])
@@ -116,7 +116,7 @@   , expectBT (Val (4,("aa",'x'))) $ pl @'(4,'(Fst,Snd)) ("aa",'x')
   , expectBT (Val (4,"aa",'x')) $ pl @'(4,Fst,Snd) ("aa",'x')
   , expectBT (Val (map ModifiedJulianDay [0,1,2,3,4,5])) $ pl @(Fst ... Snd) (ModifiedJulianDay 0, ModifiedJulianDay 5)
-  , expectBT (Val (4,'x')) $ pl @('(,) 4 %% Char1 "x") ()
+  , expectBT (Val (4,'x')) $ pl @('(,) 4 %% C "x") ()
   , expectBT (Val (4,"abc")) $ pl @('(,) %% 4 %% "abc") ()
   , expectBT (Val ("abc",4)) $ pl @(4 %& "abc" %& '(,)) ()
   , expectBT (Val ("abc",4)) $ pl @(FlipT '(,) 4 "abc") ()
@@ -187,7 +187,7 @@ 
 type Fizzbuzzs = Map Fizzbuzz
 type Fizzbuzzs2 = Map (Fizzbuzz >> If (Null' Snd) (MkLeft String Fst) (MkRight Int Snd))
--- best one cos leverages type info to determine Either a b
+-- best one as it leverages type info to determine Either a b
 type Fizzbuzzs3 = Map (Fizzbuzz >> If (Snd == "") (MkLeft' Snd Fst) (MkRight' Fst Snd))
 
 type Ip6Test = Resplit ":"
test/TestRefined2.hs view
@@ -58,7 +58,7 @@ 
 unnamedTests :: [IO ()]
 unnamedTests = [
-    (@?=) [(unsafeRefined2 255 "ff", "")] (reads @(Refined2 OAN (ReadBase Int 16) (0 <..> 0xff) String) "Refined2 255 \"ff\"") -- escape quotes cos read instance for String
+    (@?=) [(unsafeRefined2 255 "ff", "")] (reads @(Refined2 OAN (ReadBase Int 16) (0 <..> 0xff) String) "Refined2 255 \"ff\"") -- escape quotes as it is a read instance for String
   , (@?=) [] (reads @(Refined2 OAN (ReadBase Int 16) (0 <..> 0xff) String) "Refined2 256 \"100\"")
   , (@?=) [(unsafeRefined2 (-1234) "-4d2", "")] (reads @(Refined2 OAN (ReadBase Int 16) (Id < 0) String) "Refined2 (-1234) \"-4d2\"")
   , (@?=) (Right (unsafeRefined2 [1,2,3,4] "1.2.3.4")) (newRefined2 "1.2.3.4" :: Either Msg2 (Ip4R OAN))
@@ -161,7 +161,7 @@   , expect2 (Left $ XTF [1,2,3,4,5,6,7,8,9,0,1] "invalid checkdigit") $ runIdentity $ eval2P (luhn11 @OZ) "12345678901"
   ]
 
--- better to use Guard for op boolean check cos we get better errormessages
+-- better to use Guard for op boolean check as we get better error messages
 -- 1. packaged up as a promoted tuple
 type Tst3 (opts :: Opt) = '(opts, Map' (ReadP Int Id) (Resplit "\\."), (Len == 4) && All (0 <..> 0xff), String)
 
@@ -342,7 +342,7 @@      (Int,Int,String))
 testKindSignature2E = newRefined2 (1,2,"defghi")
 
--- awkward cos FoldMap t p has p for location of stuff and then we need to run in a context (usually Id relative to p)
+-- awkward as  FoldMap t p has p for location of stuff and then we need to run in a context (usually Id relative to p)
 testKindSignature2F :: Either Msg2
    (Refined2 OU
      (Second (Map (ReadP Int '[Id])))
test/TestRefined3.hs view
@@ -59,7 +59,7 @@ 
 unnamedTests :: [IO ()]
 unnamedTests = [
-    (@?=) [(unsafeRefined3 255 "ff", "")] (reads @(Refined3 OAN (ReadBase Int 16) (Between 0 255 Id) (ShowBase 16) String) "Refined3 255 \"ff\"") -- escape quotes cos read instance for String
+    (@?=) [(unsafeRefined3 255 "ff", "")] (reads @(Refined3 OAN (ReadBase Int 16) (Between 0 255 Id) (ShowBase 16) String) "Refined3 255 \"ff\"") -- escape quotes because it is a read instance for String
   , (@?=) [] (reads @(Refined3 OAN (ReadBase Int 16) (Between 0 255 Id) (ShowBase 16) String) "Refined3 256 \"100\"")
   , (@?=) [(unsafeRefined3 (-1234) "-4d2", "")] (reads @(Refined3 OAN (ReadBase Int 16) (Id < 0) (ShowBase 16) String) "Refined3 (-1234) \"-4d2\"")