CreatingRhythms-1.8.0.7
Copyright(c) Eric Bailey 2025
LicenseMIT
Maintainereric@ericb.me
Stabilityexperimental
PortabilityPOSIX
Safe HaskellSafe-Inferred
LanguageGHC2021

Data.Rhythm.Internal

Description

 
Synopsis

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]]

Vectors

cycleVector :: forall m n a. (KnownNat m, KnownNat n) => Vector n a -> Vector m a Source #

Cycle a vector of length n to produce a vector of length m.

Conceptually take m . cycle, but for Vectors.