Copyright | (c) Eric Bailey 2025 |
---|---|
License | MIT |
Maintainer | eric@ericb.me |
Stability | experimental |
Portability | POSIX |
Safe Haskell | Safe-Inferred |
Language | GHC2021 |
Data.Rhythm.Internal
Description
Synopsis
- countParts :: (Integral a, Bits a) => Int -> a -> [Int]
- padUpTo :: Num a => Int -> [a] -> [a]
- binaryDigit :: Parser (Finite 2)
- nodesToNecklaces :: Int -> [Integer] -> [[Int]]
- cycleVector :: forall m n a. (KnownNat m, KnownNat n) => Vector n a -> Vector m a
Digits
countParts :: (Integral a, Bits a) => Int -> a -> [Int] Source #
Count the parts in the n-digit little-endian binary representation of x.
A part is the length of a substring \(10^*\) composing the necklace. For example the necklace \(10100\) has parts sizes \(2\) and \(3\).
>>>
countParts 5 5
[2,3]
padUpTo :: Num a => Int -> [a] -> [a] Source #
Right pad a list with zeros up to a given length.
>>>
padUpTo 5 [0,1]
[0,1,0,0,0]
Parsers
binaryDigit :: Parser (Finite 2) Source #
Parse a binary digit, i.e., 0
or 1
.
>>>
parseString binaryDigit mempty "0"
Success (finite 0)
>>>
parseString binaryDigit mempty "1"
Success (finite 1)
>>>
parseString binaryDigit mempty "?"
Failure (ErrInfo {_errDoc = (interactive):1:1: error: expected: one, zero 1 | ?<EOF> | ^ , _errDeltas = [Columns 0 0]})
Necklaces
nodesToNecklaces :: Int -> [Integer] -> [[Int]] Source #
Convert a list of nodes to binary necklaces of a given length.
>>>
nodesToNecklaces 4 [3,5]
[[1,1,0,0],[1,0,1,0]]