[Haskell-cafe] A brief note on n_k patterns and Hackage

j3h joshhoyt at gmail.com
Tue May 5 12:22:45 EDT 2009


On Mon, May 4, 2009 at 5:23 PM, John Van Enk <vanenkj at gmail.com> wrote:
> Which package?

In 1251 packages, I found 20 source files out of 15144 source files
that use (n+k) patterns:

queuelike-1.0.9/Data/Queue/Stack.hs
queuelike-1.0.9/Data/Queue/TrieQueue.hs
hinze-streams-1.0/Data/Stream/Hinze/Stream.hs
compression-0.1/Codec/Compression/Utils.hs
bytestring-0.9.1.4/tests/lazybuildcons.hs
bytestring-0.9.1.4/tests/lazybuild.hs
liboleg-0.1.1/Language/TypeLC.hs
pqueue-mtl-1.0.7/Data/Queue/Stack.hs
pqueue-mtl-1.0.7/Data/Queue/Queue.hs
IOSpec-0.2/examples/Echo.hs
pxsl-tools-1.0.1/src/PxsltFormat.hs
pdf2line-0.0.1/pdf2line.hs
stream-fusion-0.1.2.1/tests/Test/SmallCheck/Partial.hs
queue-0.1.1.3/src/Data/Queue/Instances/STM.hs
frag-1.1.2/src/AFRP.hs
th-fold-0.0.0.1/src/Language/Haskell/TH/Fold.hs
tetris-0.27178/Util.hs
random-fu-0.0.0.2/src/Data/Random/Distribution/Binomial.hs
random-fu-0.0.0.2/src/Data/Random/Source/PureMT.hs

The method that I used to extract them may have missed some files
(e.g. anything that is Haskell source but needs to be preprocessed),
but I just wanted to save people the trouble of finding them
themselves ;)

j3h

--
For the curious, those who wish to search other sources, or those who
wish to improve on my results, I found these by I downloaded the full
Hackage tarball, unpacked it and ran:

find ./ -type f \( -name \*.hs -o \*.lhs \) | xargs npk

where npk is the following program:

> import System.Environment ( getArgs )
> import Control.Monad ( when )
> import Data.Generics ( cast, GenericQ, gcount )
> import Language.Haskell.Exts ( Module, ParseResult(..), Pat(..), parseFile )

> isNPlusK :: GenericQ Bool
> isNPlusK x = case cast x of
>                Just (PNPlusK _ _) -> True
>                _ -> False

> hasNPlusK :: Module -> Bool
> hasNPlusK = (> 0) . gcount isNPlusK

> printIfNPlusK :: FilePath -> IO ()
> printIfNPlusK fn = do
>   res <- parseFile fn
>   case res of
>     ParseOk mod -> when (hasNPlusK mod) $ putStrLn fn
>     _ -> return ()

> main :: IO ()
> main = mapM_ printIfNPlusK =<< getArgs


More information about the Haskell-Cafe mailing list