Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- smallLength ∷ Int
- sublistN ∷ Int → [a] → Gen [a]
- toMaxChunkNumber ∷ Int → Int
- toChunkNumber ∷ Int → Int → Int
- toChunkFrequencies ∷ Int → [(Int, Int)]
- toChunks ∷ [Int] → [a] → [[a]]
- multiSplit1In ∷ Int → [a] → Gen [NonEmptyList a]
- multiSplit1 ∷ [a] → Gen [NonEmptyList a]
- halve ∷ Bool → [a] → ([a], [a])
- insertManyPreferRight ∷ ∀ a. Bool → Double → a → [a] → Gen [a]
- insertManyPreferLeft ∷ Bool → Double → a → [a] → Gen [a]
- insertManyPreferEnds ∷ Double → a → [a] → Gen [a]
- multiSplit0 ∷ Double → [a] → Gen [[a]]
Documentation
Up to what length a list is considered "short".
sublistN ∷ Int → [a] → Gen [a] Source #
Generate a sublist of the given size of the given list. Preserves the order of elements.
toMaxChunkNumber ∷ Int → Int Source #
Calculate the maximum number of chunks to split a list of the given list into.
toChunkNumber ∷ Int → Int → Int Source #
Calculate the number of ways to divide a list of length len
into chunkNum
chunks.
Equals to C(len - 1, chunksNum - 1)
.
toChunkFrequencies ∷ Int → [(Int, Int)] Source #
Return a list of pairs, each of which consists of
- the frequency at which a chunk length needs to be picked by the generation machinery
- the chunk length itself
>>>
toChunkFrequencies (-1)
[]>>>
toChunkFrequencies 0
[]>>>
toChunkFrequencies 1
[(1,1)]>>>
toChunkFrequencies 5
[(1,1),(4,2),(6,3),(4,4),(1,5)]>>>
toChunkFrequencies 10
[(3,1),(6,2),(9,3),(12,4),(15,5),(18,6),(21,7)]>>>
toChunkFrequencies 50
[(3,1),(4,2),(5,3),(6,4),(7,5),(8,6),(9,7),(10,8),(11,9),(12,10),(13,11),(14,12),(15,13)]
toChunks ∷ [Int] → [a] → [[a]] Source #
Split the given list in chunks. The length of each chunk, apart from the final one, is taken from the first argument.
>>>
toChunks [3, 1] "abcdef"
["abc","d","ef"]
multiSplit1In ∷ Int → [a] → Gen [NonEmptyList a] Source #
Split a list into the given number of chunks. Concatenating the resulting lists gives back the original one. Doesn't generate empty chunks.
multiSplit1 ∷ [a] → Gen [NonEmptyList a] Source #
Split a list into chunks at random. Concatenating the resulting lists gives back the original one. Doesn't generate empty chunks.
halve ∷ Bool → [a] → ([a], [a]) Source #
Return the left and the right halves of the given list. The first argument controls whether the middle element of a list having an odd length goes into the left half or the right one.
>>>
halve True [1 :: Int]
([1],[])>>>
halve True [1, 2 :: Int]
([1],[2])>>>
halve True [1, 2, 3 :: Int]
([1,2],[3])>>>
halve False [1 :: Int]
([],[1])>>>
halve False [1, 2 :: Int]
([1],[2])>>>
halve False [1, 2, 3 :: Int]
([1],[2,3])
insertManyPreferRight ∷ ∀ a. Bool → Double → a → [a] → Gen [a] Source #
Insert a value into a list an arbitrary number of times. The first argument controls whether to allow inserting at the beginning of the list, the second argument is the probability of inserting an element at the end of the list.
insertManyPreferLeft ∷ Bool → Double → a → [a] → Gen [a] Source #
Insert a value into a list an arbitrary number of times. The first argument controls whether to allow inserting at the end of the list, the second argument is the probability of inserting an element at the beginning of the list.
insertManyPreferEnds ∷ Double → a → [a] → Gen [a] Source #
Insert a value into a list an arbitrary number of times. The first argument is the probability
of inserting an element at an end of the list (i.e. either the beginning or the end, not
combined). See multiSplit1
for what this function allows us to do.
multiSplit0 ∷ Double → [a] → Gen [[a]] Source #
Split a list into chunks at random. Concatenating the resulting lists gives back the original one. Generates empty chunks. The first argument is the probability of generating at least one empty chunk as the first element of the resulting list. It is also the probability of generating an empty chunk as the last element of the resulting list. The probability of generating empty chunks decreases as we go from either of the ends of the resulting list (this is so that we are more likely to hit a corner case related to handling elements at the beginning or the end of a list).