Safe Haskell | None |
---|---|
Language | Haskell2010 |
semigroup / monoid expressions
similar to <>
>>>
pz @(Fst Id <> Snd Id) ("abc","def")
PresentT "abcdef"
>>>
pz @("abcd" <> "ef" <> Id) "ghi"
PresentT "abcdefghi"
>>>
pz @("abcd" <> "ef" <> Id) "ghi"
PresentT "abcdefghi"
>>>
pz @(Wrap (SG.Sum _) Id <> FromInteger _ 10) 13
PresentT (Sum {getSum = 23})
>>>
pz @(Wrap (SG.Product _) Id <> FromInteger _ 10) 13
PresentT (Product {getProduct = 130})
>>>
pz @('(FromInteger _ 10,"def") <> Id) (SG.Sum 12, "_XYZ")
PresentT (Sum {getSum = 22},"def_XYZ")
>>>
pz @(SapA' (SG.Max _)) (10,12)
PresentT (Max {getMax = 12})
>>>
pz @(SapA' (SG.Sum _)) (10,12)
PresentT (Sum {getSum = 22})
>>>
pl @((Id <> Id) >> Unwrap Id) (SG.Sum 12)
Present 24 ((>>) 24 | {getSum = 24}) PresentT 24
similar to mconcat
>>>
pz @(MConcat Id) [SG.Sum 44, SG.Sum 12, SG.Sum 3]
PresentT (Sum {getSum = 59})
>>>
pz @(Map '(Pure SG.Sum Id, Pure SG.Max Id) Id >> MConcat Id) [7 :: Int,6,1,3,5] -- monoid so need eg Int
PresentT (Sum {getSum = 22},Max {getMax = 7})
similar to sconcat
>>>
pz @(ToNEList >> SConcat Id) [SG.Sum 44, SG.Sum 12, SG.Sum 3]
PresentT (Sum {getSum = 59})
>>>
pz @(Map '(Pure SG.Sum Id, Pure SG.Max Id) Id >> ToNEList >> SConcat Id) [7,6,1,3,5]
PresentT (Sum {getSum = 22},Max {getMax = 7})
similar to stimes
>>>
pz @(STimes 4 Id) (SG.Sum 3)
PresentT (Sum {getSum = 12})
>>>
pz @(STimes 4 Id) "ab"
PresentT "abababab"
>>>
pl @(STimes 4 Id) (SG.Sum 13)
Present Sum {getSum = 52} (STimes 4 p=Sum {getSum = 13} Sum {getSum = 52} | n=4 | Sum {getSum = 13}) PresentT (Sum {getSum = 52})
>>>
pl @(STimes (Fst Id) (Snd Id)) (4,['x','y'])
Present "xyxyxyxy" (STimes 4 p="xy" "xyxyxyxy" | n=4 | "xy") PresentT "xyxyxyxy"
>>>
pl @(STimes (Fst Id) (Snd Id)) (4,"abc")
Present "abcabcabcabc" (STimes 4 p="abc" "abcabcabcabc" | n=4 | "abc") PresentT "abcabcabcabc"
>>>
pl @(STimes 4 Id) "abc"
Present "abcabcabcabc" (STimes 4 p="abc" "abcabcabcabc" | n=4 | "abc") PresentT "abcabcabcabc"
semigroup append both sides of a tuple (ie uncurry (<>))
>>>
pz @(Snd Id >> SapA) (4,("abc","def"))
PresentT "abcdef"
data SapA' (t :: Type) Source #
semigroup append both sides of a tuple (ie uncurry (<>)) using Wrap
>>>
pl @(SapA' (SG.Sum _) >> Unwrap Id) (4,5)
Present 9 ((>>) 9 | {getSum = 9}) PresentT 9
data MEmptyT (t :: Type) Source #
similar to mempty
>>>
pz @(MEmptyT (SG.Sum Int)) ()
PresentT (Sum {getSum = 0})
>>>
pl @(MEmptyT _ ||| Ones Id) (Right "abc")
Present ["a","b","c"] ((|||) Right ["a","b","c"] | "abc") PresentT ["a","b","c"]
>>>
pl @(MEmptyT _ ||| Ones Id) (Left ["ab"])
Present [] ((|||) Left [] | ["ab"]) PresentT []
>>>
pl @(MEmptyT (Maybe ())) 'x'
Present Nothing (MEmptyT Nothing) PresentT Nothing
similar to mempty
>>>
pl @(MEmptyT' Id) (Just (SG.Sum 12))
Present Nothing (MEmptyT Nothing) PresentT Nothing
>>>
pl @(MEmptyT (SG.Sum _) >> Unwrap Id >> Id + 4) ()
Present 4 ((>>) 4 | {0 + 4 = 4}) PresentT 4
creates a mempty value for the proxy
>>>
pl @('Proxy >> MEmptyP) "abc"
Present "" ((>>) "" | {MEmptyT ""}) PresentT ""
data MEmpty2 (t :: Type) Source #
lift mempty over a Functor
>>>
pz @(MEmpty2 (SG.Product Int)) [Identity (-13), Identity 4, Identity 99]
PresentT [Product {getProduct = 1},Product {getProduct = 1},Product {getProduct = 1}]
>>>
pl @(MEmpty2 (SG.Sum _)) (Just ())
Present Just (Sum {getSum = 0}) (MEmpty2 Just (Sum {getSum = 0}) | Just ()) PresentT (Just (Sum {getSum = 0}))