Stability | provisional |
---|---|
Maintainer | Hugo Pacheco <hpacheco@nii.ac.jp> |
Safe Haskell | None |
Collection of put-based programming examples
- unzipPut :: (Monad m, Eq a, Eq b) => PutlensM m ([a], [b]) [(a, b)]
- mapPut :: (Monad m, Eq a) => PutlensM m b a -> PutlensM m [b] [a]
- unfoldrPut :: (Monad m, Eq a, Eq b) => PutlensM m (b, a) a -> a -> PutlensM m [b] a
- unfoldrsPut :: (Monad m, Eq a, Eq b) => PutlensM m (b, a) a -> a -> PutlensM m [b] a
- nilPut :: Monad m => PutlensM m [a] ()
- consPut :: Monad m => PutlensM m [a] (a, [a])
- unnilPut :: Monad m => PutlensM m () [a]
- unconsPut :: Monad m => PutlensM m (a, [a]) [a]
- unheadPut :: (Monad m, Eq a) => PutlensM m [a] a
- untailPut :: (Monad m, Eq a) => PutlensM m [a] [a]
- keepfstPut2 :: (Monad m, Eq v) => PutlensM m (s1, v) v
- wrapPut :: (Monad m, Eq a) => PutlensM m [a] a
- unwrapPut :: (Monad m, Eq a) => PutlensM m a [a]
- data Tree a
- unnodePut :: forall m a. Monad m => PutlensM m (a, (Tree a, Tree a)) (Tree a)
- nodePut :: forall m a. Monad m => PutlensM m (Tree a) (a, (Tree a, Tree a))
- unemptyPut :: forall m a. Monad m => PutlensM m () (Tree a)
- emptyPut :: forall m a. Monad m => PutlensM m (Tree a) ()
- catPut :: (Monad m, Eq a) => PutlensM m ([a], [a]) [a]
- exCatPut1 :: [Integer]
- exCatPut2 :: Identity ([Integer], [Integer])
- exCatPut3 :: Identity ([Integer], [Integer])
- exCatPut4 :: Identity ([Integer], [Integer])
- catPutN :: (Monad m, Eq a) => (Maybe ([a], [a]) -> [a] -> Int) -> PutlensM m ([a], [a]) [a]
- catPutN' :: (Monad m, Eq a) => PutlensStateM m Int ([a], [a]) [a]
- catPut2 :: PutlensM Identity ([Integer], [Integer]) [Integer]
- exCatPut21 :: [Integer]
- exCatPut22 :: Identity ([Integer], [Integer])
- exCatPut23 :: Identity ([Integer], [Integer])
- exCatPut24 :: Identity ([Integer], [Integer])
- catPutP :: (Monad m, Eq a) => (Maybe (Either [a] [a]) -> a -> m Bool) -> PutlensM m ([a], [a]) [a]
- catPutSame :: (Monad m, Eq a) => PutlensM m ([a], [a]) [a]
- exCatPutSame1 :: [Integer]
- exCatPutSame2 :: Identity ([Integer], [Integer])
- exCatPutSame3 :: Identity ([Integer], [Integer])
- catPutPred :: (Monad m, Ord a) => a -> PutlensM m ([a], [a]) [a]
- exCatPutPred1 :: [Integer]
- exCatPutPred2 :: Identity ([Integer], [Integer])
- exCatPutPred3 :: Identity ([Integer], [Integer])
- exCatPutPred4 :: Identity ([Integer], [Integer])
- filterlPut :: (Monad m, Eq a, Eq b) => PutlensM m [Either a b] [a]
- filterrPut :: (Monad m, Eq a, Eq b) => PutlensM m [Either a b] [b]
- filterPut :: (Monad m, Eq a, Eq b) => Bool -> PutlensM m [Either a b] ([a], [b])
- filterleftPut :: (Monad m, Eq a, Eq b) => PutlensM m [Either a b] [a]
- filterrightPut :: (Monad m, Eq a, Eq b) => PutlensM m [Either a b] [b]
- succPut :: Monad m => PutlensM m Int Int
- predPut :: Monad m => PutlensM m Int Int
- data Nat
- unsuccNPut :: forall m. Monad m => PutlensM m Nat Nat
- succNPut :: forall m. Monad m => PutlensM m Nat Nat
- unzeroNPut :: forall m. Monad m => PutlensM m () Nat
- zeroNPut :: forall m. Monad m => PutlensM m Nat ()
- natPut :: Monad m => PutlensM m Nat Int
- int :: Nat -> Int
- nat :: Int -> Nat
- lengthNatPut :: (Monad m, Eq a) => (Int -> a) -> PutlensM m [a] Nat
- exLengthNatPut1 :: Nat
- exLengthNatPut2 :: Identity [Char]
- exLengthNatPut3 :: Identity [Char]
- embedAtPut :: (Monad m, Eq a) => Int -> PutlensM m [a] a
- embedAtPut1 :: (Monad m, Eq a) => Int -> PutlensM m [a] a
- embedAtPut2 :: (Monad m, Eq a) => Int -> PutlensM m [a] a
- embedAtPut2' :: (Monad m, Eq a) => PutlensM m (Int, [a]) a
- embedAtPut3 :: (Monad m, Eq a) => Int -> PutlensM m [a] a
- embedAtPut3' :: (Monad m, Eq a) => PutlensStateM m a (Int, [a]) a
- exEmbedAtPut1 :: Char
- exEmbedAtPut2 :: Identity [Char]
- exEmbedAtPut3 :: Identity [Char]
- exEmbedAtPut4 :: Char
- exEmbedAtPut5 :: Identity [Char]
- embedAtPut4 :: (Monad m, Eq a) => Int -> PutlensM m [a] a
- splitAtPut :: (Monad m, Eq a) => PutlensM m (Int, [a]) ([a], [a])
- exEmbedAtPut41 :: Char
- exEmbedAtPut42 :: Identity [Char]
- exEmbedAtPut43 :: Identity [Char]
- splitPut :: (Monad m, Integral a) => (a -> a -> m a) -> PutlensM m (a, a) a
- summandsPut1 :: (Monad m, Integral a) => PutlensM m [a] a
- summandsPut2 :: (Monad m, Integral a) => PutlensM m [a] a
- summandsPut3 :: (Monad m, Integral a) => PutlensM m [a] a
- summandsPut3' :: (Monad m, Integral a) => PutlensStateM m a [a] a
- summandsPut4 :: (Monad m, Integral a) => PutlensM m [a] a
- summandsPut4' :: (Monad m, Integral a) => PutlensStateM m a [a] a
- exSummandsPut1 :: Integer
- exSummandsPut2 :: [Integer]
- exSummandsPut3 :: [Integer]
- exSummandsPut4 :: [Integer]
- exSummandsPut5 :: [Integer]
- exSummandsPut6 :: [Integer]
- exSummandsPut7 :: [Integer]
- replicatePut :: (Monad m, Eq a) => PutlensM m (a, Int) [a]
- exReplicatePut1 :: Identity (Char, Int)
- exReplicatePut2 :: Identity (Char, Int)
- replicateListPut :: (Monad m, Eq a) => PutlensM m [(a, Int)] [a]
- recoverzerosPut :: (Monad m, Eq a) => PutlensM m [(a, Int)] [(a, Int)]
- splitListPut :: (Monad m, Eq a) => PutlensM m [[a]] [a]
- exReplicateListPut1 :: [Char]
- exReplicateListPut2 :: Identity [(Char, Int)]
- halvePut :: (Monad m, Eq a) => a -> PutlensM m [a] [a]
- exHalvePut1 :: Identity [Char]
- exHalvePut2 :: Identity [Char]
- halvePut2 :: (Monad m, Eq a) => a -> PutlensM m [a] [a]
- halvePut2' :: (Monad m, Eq a) => a -> PutlensM m ([a], Int) ([a], Int)
- exHalvePut21 :: Identity [Char]
- exHalvePut22 :: Identity [Char]
- exHalvePut23 :: Identity [Char]
- halvePut3 :: (Monad m, Eq a) => a -> PutlensM m [a] [a]
- halvePut3' :: (Monad m, Eq a) => a -> PutlensStateM m Int ([a], Int) [a]
- exHalvePut31 :: Identity [Char]
- exHalvePut32 :: Identity [Char]
- exHalvePut33 :: Identity [Char]
- isumPut :: Monad m => PutlensM m [Int] [Int]
- subtractPut :: Monad m => Int -> PutlensM m Int Int
- exIsumPut1 :: [Int]
- exIsumPut2 :: Identity [Int]
- iunsortPut1 :: (Monad m, Ord a) => PutlensM m [a] [a]
- delPut1 :: (Monad m, Ord a) => PutlensM m (a, [a]) [a]
- iunsortPut2 :: (Monad m, Ord a) => PutlensM m [a] [a]
- delPut2 :: (Monad m, Ord a) => PutlensM m (a, [a]) [a]
- exIunsortPut1 :: [Integer]
- exIunsortPut2 :: [Integer]
- exIunsortPut3 :: [Integer]
- qsortPut :: (Monad m, Ord a) => PutlensM m [a] [a]
- partitionPut :: (Monad m, Ord a) => PutlensM m (a, [a]) (a, ([a], [a]))
- catPutNonEmptyRight :: (Monad m, Eq a) => PutlensM m ([a], [a]) [a]
- exQsortPut1 :: [Integer]
- exQsortPut2 :: Identity [Integer]
- exQsortPut3 :: Identity [Integer]
- positionsPut :: (Monad m, Eq a) => PutlensM m [a] [(Pos, a)]
- positionsPut' :: (Monad m, Eq a) => Pos -> PutlensM m [a] [(Pos, a)]
- positionsPut2 :: (Monad m, Eq a) => PutlensM m [a] [(Pos, a)]
- positionsPut2' :: (Monad m, Eq a) => PutlensReaderM m [(Pos, a)] (Int, [a]) [(Pos, a)]
- exPositions1 :: [(Pos, Char)]
- exPositions2 :: [Char]
- exPositions3 :: [Char]
- appendWithSepPut :: Monad m => String -> PutlensM m (String, String) String
- readPut :: (MonadPlus m, Read a, Show a) => PutlensM m a String
- unwordsIntBool :: PutlensM Maybe [Either Int Bool] String
- unwordsPut :: PutlensM Maybe [String] String
- unfoldr1Put :: (MonadPlus m, Eq a) => PutlensM m (a, a) a -> PutlensM m [a] a
- type Pos = Int
- segments :: [a] -> [[a]]
- mssPut :: Monad m => PutlensM m [Int] Int
- mssPut' :: Monad m => Bool -> PutlensM (ReaderT Int m) [Int] Int
- maxSumSegsPut :: Monad m => PutlensReaderM m Int (Map Pos Int, [[Pos]]) Int
- maxSumSegsPut' :: Monad m => PutlensStateM (ReaderT Int m) Bool (Map Pos Int, [[Pos]]) Int
- lookupSegPut :: (Monad m, Eq a) => PutlensM m (Map Int a, [Int]) [a]
- lookupIntMapPut :: (Monad m, Eq a) => PutlensM m (Int, Map Int a) a
- maxPut :: Monad m => PutlensStateM (ReaderT Int m) Bool (Int, Int) Int
- fromListPut :: (Monad m, Eq a, Ord k) => PutlensM m [(k, a)] (Map k a)
- toListPut :: (Monad m, Eq a, Ord k) => PutlensM m (Map k a) [(k, a)]
- exMssPut1 :: Int
- exMssPut2 :: [Int]
- exMssPut3 :: [Int]
- exMssPut4 :: [Int]
- exMssPut5 :: [Int]
Lists
unzipPut :: (Monad m, Eq a, Eq b) => PutlensM m ([a], [b]) [(a, b)]Source
Unzips a list into two lists (creating empty tail lists by default)
unfoldrPut :: (Monad m, Eq a, Eq b) => PutlensM m (b, a) a -> a -> PutlensM m [b] aSource
Putlens version of foldr
unfoldrsPut :: (Monad m, Eq a, Eq b) => PutlensM m (b, a) a -> a -> PutlensM m [b] aSource
Variant of unfoldrPut
that tries to present the original source branching even when the view value matches the stop condition
Useful for example for cases when we want to always preserve the length of the original source list.
Constructor/destructor putlenses for lists
keepfstPut2 :: (Monad m, Eq v) => PutlensM m (s1, v) vSource
example of automatically deriving constructor/destructor putlenses for binary trees
unemptyPut :: forall m a. Monad m => PutlensM m () (Tree a)Source
List concatenation
catPutN :: (Monad m, Eq a) => (Maybe ([a], [a]) -> [a] -> Int) -> PutlensM m ([a], [a]) [a]Source
List concatenation (split the view list at position n-1)
catPut2 :: PutlensM Identity ([Integer], [Integer]) [Integer]Source
List concatenation (split the view list in half)
exCatPut21 :: [Integer]Source
exCatPut22 :: Identity ([Integer], [Integer])Source
exCatPut23 :: Identity ([Integer], [Integer])Source
exCatPut24 :: Identity ([Integer], [Integer])Source
catPutP :: (Monad m, Eq a) => (Maybe (Either [a] [a]) -> a -> m Bool) -> PutlensM m ([a], [a]) [a]Source
List concatenation (puts elements to the left while satisfying a predicate)
catPutSame :: (Monad m, Eq a) => PutlensM m ([a], [a]) [a]Source
List concatenation (puts elements to the left while being equal)
exCatPutSame2 :: Identity ([Integer], [Integer])Source
exCatPutSame3 :: Identity ([Integer], [Integer])Source
catPutPred :: (Monad m, Ord a) => a -> PutlensM m ([a], [a]) [a]Source
List concatenation (puts elements to the left while smaller than a particular value)
exCatPutPred2 :: Identity ([Integer], [Integer])Source
exCatPutPred3 :: Identity ([Integer], [Integer])Source
exCatPutPred4 :: Identity ([Integer], [Integer])Source
filterlPut :: (Monad m, Eq a, Eq b) => PutlensM m [Either a b] [a]Source
Left list filtering lens (but will drop some right elements if the view list is smaller).
The argument passed to keepfstOrPut
can be undefined because it will never be used
filterrPut :: (Monad m, Eq a, Eq b) => PutlensM m [Either a b] [b]Source
Right list filtering lens (but will drop some left elements if the view list is smaller).
The argument passed to keepsndOrPut
can be undefined because it will never be used
filterPut :: (Monad m, Eq a, Eq b) => Bool -> PutlensM m [Either a b] ([a], [b])Source
List filtering lens that splits a list of eithers into a list two lists. The boolean argument allows controlling the priority of left/right values in the source list.
filterleftPut :: (Monad m, Eq a, Eq b) => PutlensM m [Either a b] [a]Source
Left list filtering lens (that recovers all right elements).
filterrightPut :: (Monad m, Eq a, Eq b) => PutlensM m [Either a b] [b]Source
Right list filtering lens (that recovers all left elements).
Integers
Naturals
unzeroNPut :: forall m. Monad m => PutlensM m () NatSource
List length
exLengthNatPut2 :: Identity [Char]Source
exLengthNatPut3 :: Identity [Char]Source
List lookup
embedAtPut :: (Monad m, Eq a) => Int -> PutlensM m [a] aSource
Embeds a value at a fixed position in a list
embedAtPut1 :: (Monad m, Eq a) => Int -> PutlensM m [a] aSource
Embeds a value at a fixed position in a list (supports extending the length original list)
embedAtPut2 :: (Monad m, Eq a) => Int -> PutlensM m [a] aSource
Embeds a value at a fixed position in a list (source induction)
embedAtPut3 :: (Monad m, Eq a) => Int -> PutlensM m [a] aSource
Embeds a value at a fixed position in a list (supports extending the length original list) (source induction)
embedAtPut3' :: (Monad m, Eq a) => PutlensStateM m a (Int, [a]) aSource
exEmbedAtPut2 :: Identity [Char]Source
exEmbedAtPut3 :: Identity [Char]Source
exEmbedAtPut5 :: Identity [Char]Source
embedAtPut4 :: (Monad m, Eq a) => Int -> PutlensM m [a] aSource
Embeds a value at a fixed position in a list (splitAt approach)
exEmbedAtPut42 :: Identity [Char]Source
exEmbedAtPut43 :: Identity [Char]Source
List summation
splitPut :: (Monad m, Integral a) => (a -> a -> m a) -> PutlensM m (a, a) aSource
Splits a view number into two summands (by adding an offset to the original first value)
summandsPut1 :: (Monad m, Integral a) => PutlensM m [a] aSource
Updates the sum of a list (preserves the original source and appends the difference to the end)
summandsPut2 :: (Monad m, Integral a) => PutlensM m [a] aSource
Updates the sum of a list (distributes the difference by dividing it by two at each recursive step) half of the difference is added to the first element of the source, a quarter to the second, and so on until the remainder is 0
summandsPut3 :: (Monad m, Integral a) => PutlensM m [a] aSource
Updates the sum of a list (distributes the difference by dividing it by the length of the original list) distributes the difference evenly among original list numbers
summandsPut3' :: (Monad m, Integral a) => PutlensStateM m a [a] aSource
summandsPut4 :: (Monad m, Integral a) => PutlensM m [a] aSource
Updates the sum of a list (distributes the difference by dividing it by the length of the original list, always preserving the size f the original list even when the view is zero)
summandsPut4' :: (Monad m, Integral a) => PutlensStateM m a [a] aSource
Replicate
exReplicatePut1 :: Identity (Char, Int)Source
exReplicatePut2 :: Identity (Char, Int)Source
replicateListPut :: (Monad m, Eq a) => PutlensM m [(a, Int)] [a]Source
Replicates a list of elements into a sequence of replicated elements
splitListPut :: (Monad m, Eq a) => PutlensM m [[a]] [a]Source
exReplicateListPut2 :: Identity [(Char, Int)]Source
Halve
halvePut :: (Monad m, Eq a) => a -> PutlensM m [a] [a]Source
Takes the first half of a list (with a default empty element)
exHalvePut1 :: Identity [Char]Source
exHalvePut2 :: Identity [Char]Source
halvePut2 :: (Monad m, Eq a) => a -> PutlensM m [a] [a]Source
Takes the first half of a list (using an increasing counter with each consumed element in the forward direction)
exHalvePut21 :: Identity [Char]Source
exHalvePut22 :: Identity [Char]Source
exHalvePut23 :: Identity [Char]Source
halvePut3 :: (Monad m, Eq a) => a -> PutlensM m [a] [a]Source
Takes the first half of a list (using a decreasing counter with the size of the input list, decreased 2 by 2, in the forward direction)
halvePut3' :: (Monad m, Eq a) => a -> PutlensStateM m Int ([a], Int) [a]Source
exHalvePut31 :: Identity [Char]Source
exHalvePut32 :: Identity [Char]Source
exHalvePut33 :: Identity [Char]Source
exIsumPut1 :: [Int]Source
exIsumPut2 :: Identity [Int]Source
Sorting
iunsortPut1 :: (Monad m, Ord a) => PutlensM m [a] [a]Source
Insertion sort (put according to the original relative source order)
iunsortPut2 :: (Monad m, Ord a) => PutlensM m [a] [a]Source
Insertion sort (identity backward transformation)
qsortPut :: (Monad m, Ord a) => PutlensM m [a] [a]Source
Quicksort (put according to the original relative source order)
partitionPut :: (Monad m, Ord a) => PutlensM m (a, [a]) (a, ([a], [a]))Source
Partition a list into smaller and bigger elements than a given element
catPutNonEmptyRight :: (Monad m, Eq a) => PutlensM m ([a], [a]) [a]Source
exQsortPut1 :: [Integer]Source
exQsortPut2 :: Identity [Integer]Source
exQsortPut3 :: Identity [Integer]Source
positionsPut :: (Monad m, Eq a) => PutlensM m [a] [(Pos, a)]Source
Adds positions to a list (using an higher-order function)
positionsPut2 :: (Monad m, Eq a) => PutlensM m [a] [(Pos, a)]Source
Adds positions to a list (using environment)
positionsPut2' :: (Monad m, Eq a) => PutlensReaderM m [(Pos, a)] (Int, [a]) [(Pos, a)]Source
exPositions1 :: [(Pos, Char)]Source
exPositions2 :: [Char]Source
exPositions3 :: [Char]Source
Exception handling
appendWithSepPut :: Monad m => String -> PutlensM m (String, String) StringSource
Appends two strings with a separating space
readPut :: (MonadPlus m, Read a, Show a) => PutlensM m a StringSource
Parsingpretty-printing lens version using @read@show
unwordsIntBool :: PutlensM Maybe [Either Int Bool] StringSource
Parses a string into a sequence of Int
or Bool
values separated by a single space
unfoldr1Put :: (MonadPlus m, Eq a) => PutlensM m (a, a) a -> PutlensM m [a] aSource
Putlens inverse of foldr1
, a specialization of foldr
for non-empty lists
Maximum segment sum
mssPut :: Monad m => PutlensM m [Int] IntSource
Updating maximum segment sum when the sum increases, update only the largest segment when the sum decreases, update all segments that surpass the new maximum, from smallest to largest
maxSumSegsPut :: Monad m => PutlensReaderM m Int (Map Pos Int, [[Pos]]) IntSource