moduleRhythm(nextBin,nextDec,nextHex,nextVar)whereimportqualifiedNumericasNumimportqualifiedData.CharasChar{- The Rhythm of Counting -}count::Int->Int->Int->[Int]->[Int]countuplowval=letf[ ]=[val]f(x:xs)=casex==upofTrue->low:fxsFalse->x+1:xsinfhlp::Int->Int->Int->[Int]->Maybe[Int]hlpuplowvalxs=caseall(\x->x>=low&&x<=up)xsofTrue->Just(countuplowvalxs)False->NothingnextHlp::([Int]->Maybe[Int])->[Char]->Maybe[Char]nextHlpfxs=letys=reversexsds=mapChar.digitToIntysincasefdsofJustvs->Just(reverse(mapChar.intToDigitvs))Nothing->NothingnextBin::[Char]->Maybe[Char]nextBin=nextHlp(hlp101)nextDec::[Char]->Maybe[Char]nextDec=nextHlp(hlp901)nextHex::[Char]->Maybe[Char]nextHexxs=letys=reversexsds=mapChar.digitToIntysincasehlp0xf0x00x1dsofJustvs->Just(reverse(foldl(\av->a++Num.showHexv"")""vs))Nothing->NothingnextVar::[Char]->Maybe[Char]nextVarxs=letys=reversexscs=mapChar.ordysincasehlp1229797csofJustvs->Just(reverse(mapChar.chrvs))Nothing->Nothing
#!/usr/bin/envstack{- stack
--resolver lts-8.21
--install-ghc
runghc
--
-Wall -Werror
-}moduleMain(main)whereimportqualifiedData.ListasListimportqualifiedRhythmasRhythmmain::IO()main=let{- Infinity many unique (and optimal shortest?) variables -}vsx=List.unfoldr(\(Justv)->Just(v,Rhythm.nextVarv))(Justx)indo{- The next binary after 3 is 4: -}putStrLn(show(Just"1000"==Rhythm.nextBin"111")){- The next number after 999 is 1000: -}putStrLn(show(Just"1000"==Rhythm.nextDec"999")){- The next number after "fff" is 1000: -}putStrLn(show(Just"1000"==Rhythm.nextHex"fff")){- The next variable after "zzz" is "aaaa": -}putStrLn(show(Just"aaaa"==Rhythm.nextVar"zzz")){- We retrieve a 10 unique of the shortest variables, starting from "z" -}letten=take10(vs"z")inputStrLn(showten)