Skip to content
This repository was archived by the owner on Jul 8, 2018. It is now read-only.

Commit 3c86a00

Browse files
committed
include all the other random files I had floating around
1 parent 254591d commit 3c86a00

File tree

14 files changed

+282
-3
lines changed

14 files changed

+282
-3
lines changed

bandwidth.hs

100755100644
File mode changed.

d.hs

100755100644
File mode changed.

deletelines.hs

100755100644
File mode changed.

deps.hs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import Data.Maybe (fromJust)
2+
import Distribution.PackageDescription
3+
import Distribution.PackageDescription.Parse
4+
import Control.Monad (unless)
5+
6+
main :: IO ()
7+
main = do cbl <- getContents
8+
let desc = parsePackageDescription cbl
9+
case desc of
10+
ParseFailed _ -> return ()
11+
ParseOk _ d -> do let repos = repoPair $ extractHead $ extractRepos d
12+
let cmd = concatMap shellify repos
13+
unless (null cmd) $ putStrLn cmd
14+
15+
shellify :: (RepoType, String) -> String
16+
shellify (rt,url) = case rt of
17+
Darcs -> "darcs get " ++ url
18+
Git -> "git clone " ++ url
19+
SVN -> "svn clone " ++ url
20+
CVS -> "cvs co " ++ url
21+
Mercurial -> "hg clone " ++ url
22+
_ -> ""
23+
24+
repoPair :: [SourceRepo] -> [(RepoType, String)]
25+
repoPair = map (\x -> (fromJust $ repoType x, fromJust $ repoLocation x))
26+
27+
extractHead :: [SourceRepo] -> [SourceRepo]
28+
extractHead rs = filter (\x -> isnothing x && ishead x) rs
29+
where ishead sr = case repoKind sr of
30+
RepoHead -> True
31+
_ -> False
32+
isnothing ss = case repoType ss of
33+
Nothing -> False
34+
Just _ -> case repoLocation ss of
35+
Nothing -> False
36+
Just _ -> True
37+
38+
extractRepos :: GenericPackageDescription -> [SourceRepo]
39+
extractRepos = sourceRepos . packageDescription

echelon.hs

100755100644
File mode changed.

function-counter.hs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import qualified Data.Data
2+
import Language.Haskell.Exts
3+
import qualified Data.Foldable as F (concat)
4+
import Data.Generics.Uniplate.Data
5+
import qualified Data.Map as M
6+
import Data.List
7+
import Data.Ord
8+
9+
main :: IO ()
10+
main = do args <- fmap lines getContents
11+
db <- fmap (M.unionsWith (+)) $ mapM checkAndCount args
12+
print $ map show $ sortBy (comparing snd) $ M.toList db
13+
14+
checkAndCount :: FilePath -> IO (M.Map String Int)
15+
checkAndCount f = do putStrLn f
16+
x <- readFile f
17+
let exts = F.concat $ readExtensions x
18+
let parsed = parseFileContentsWithMode
19+
(defaultParseMode {fixities = fixes, extensions = exts}) x
20+
case parsed of
21+
ParseFailed _ _ -> return M.empty
22+
ParseOk a -> return (functionSearch a)
23+
24+
-- the default fixities augmented with everything necessary to parse my corpus
25+
fixes :: Maybe [Fixity]
26+
fixes = Just $ baseFixities ++ infixr_ 0 ["==>", "#", ">==",">>==", ">.", "$$"]
27+
28+
functionSearch :: Data.Data.Data from => from -> M.Map String Int
29+
functionSearch md = do
30+
let xs = [ a | Var (UnQual (Ident a)) <- universeBi md]
31+
M.fromListWith (+) $ zip xs (repeat 1) -- map (M.insertWith (+) xs 1 $ M.empty)

game.hs

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
{-# LANGUAGE GADTs, RankNTypes #-}
2+
--
3+
data Term x where
4+
K :: Term (a -> b -> a)
5+
S' :: Term ((a -> b -> c) -> (a -> b) -> a -> c)
6+
Const :: a -> Term a
7+
(:@) :: Term (a -> b) -> (Term a) -> Term b
8+
infixl 6 :@
9+
10+
eval'::Term a -> Term a
11+
eval' (K :@ x :@ y) = x
12+
eval' (S' :@ x :@ y :@ z) = x :@ z :@ (y :@ z)
13+
eval' x = x
14+
15+
--
16+
17+
data Term' x where
18+
E :: (Integral a => a -> Bool) -> Term' (Integral a => a -> Bool)
19+
N :: Int -> Term' Int
20+
Q :: Int -> (Integral a => a -> Bool) -> Term' ((Integral a => a -> Bool), Int)
21+
22+
eval :: Term' x -> x
23+
eval (N x) = x
24+
--eval (E x) = x
25+
-- eval (Q (x,y)) = eval x $ eval y
26+
27+
foo :: Bool
28+
foo = eval (Q odd 1)
29+
30+
-- data S x where
31+
-- Ns :: S [Int]
32+
-- Eval :: S (Int -> Bool)
33+
-- Map :: S ([Int] -> S a -> Bool)
34+
-- Even :: S (Int -> Bool)
35+
-- IsPrime :: S (Int -> Bool)
36+
-- Expr :: S (a, b)
37+
38+
-- eval :: S x -> S x
39+
-- eval (Expr (Even, Ns) = map isEven (
40+
-- eval x = x
41+
42+
--
43+
-- data Singleton a where
44+
-- Even :: Singleton (Int -> Bool)
45+
-- Odd :: Singleton (Int -> Bool)
46+
-- Prime :: Singleton (Int -> Bool)
47+
-- -- Const' :: [Int] -> Singleton [Int]
48+
49+
-- eval'
50+
51+
-- data Span a where
52+
-- Map :: Span (Singleton a -> [Int] -> Bool)
53+
54+
55+
-- data Boolean a where
56+
-- Not :: Boolean (Bool -> Bool)
57+
-- Xor :: Boolean (Bool -> Bool -> Bool)
58+
--
59+
-- -- BTW, type signatures are mandatory if you're using GADTs
60+
-- translate :: Singleton a -> a
61+
-- translate a = case a of
62+
-- Even -> not . odd
63+
-- Odd -> odd
64+
-- Prime -> isPrime
65+
66+
67+
-- functions :: [Function a] -> [a]
68+
-- functions = map translate
69+
--
70+
-- eval :: [a] -> [Function (a -> Bool)] -> Bool
71+
-- eval nums exprs = and $ zipWith (\x y -> y x) nums $ functions exprs
72+
73+
isPrime :: Int -> Bool
74+
isPrime n = aux primes
75+
where
76+
aux ps | head ps < n = aux $ tail ps
77+
| head ps == n = True
78+
| otherwise = False
79+
primes :: [Int]
80+
primes = sieve [2..]
81+
sieve (p:xs) = p : sieve [x | x <- xs, x `mod` p /= 0]
82+
sieve [] = undefined
83+
84+
{- -- apparently need GADTs for this... http://haskell.org/haskellwiki/GADT
85+
data Function = Fold |
86+
Prime | Composite |
87+
Subtract | Add | Multiply | Divide | Exponent |
88+
GreaterThan | LessThan
89+
90+
foo xs y = zipWith ($) (map translateUnadic' xs) y
91+
92+
-- translate :: Function ->[Int] -> Bool
93+
translateUnadic Not = not
94+
translateUnadic' Even = not . odd
95+
translateUnadic' Odd = odd
96+
97+
translateUnadic'' Prime = isPrime
98+
translateUnadic'' Composite = not . isPrime
99+
100+
translate And = (&&)
101+
translate Or = (||)
102+
-- translate Xor = xor
103+
104+
translate' Fold = \x y -> foldr x 0 y
105+
106+
translate'' Subtract = (-)
107+
translate'' Add = (+)
108+
-- translate'' =
109+
110+
xor :: Bool -> Bool -> Bool
111+
xor x y = (x &&not y) || (y ||not x)
112+
113+
-}

length.hs

100755100644
File mode changed.

modulecounter.hs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import System.Environment (getArgs)
2+
import Language.Haskell.Exts
3+
import qualified Data.Foldable as F (concat)
4+
import Data.Generics.Uniplate.Data
5+
6+
main :: IO ()
7+
main = do (func:_) <- getArgs
8+
args <- fmap lines $ getContents
9+
imports <- join $ mapM parseForImports args
10+
-- insert each import module into the IntMap
11+
-- print out IntMap sorting by module (descending order)
12+
13+
parseForImports :: String -> FilePath -> IO [Imports]
14+
parseForImports fn fs = do print fs
15+
x <- readFile fs
16+
let exts = F.concat $ readExtensions x
17+
let parsed = parseFileContentsWithMode (defaultParseMode { fixities = fixes, extensions = exts }) x
18+
case parsed of
19+
ParseFailed _ _ -> (return [])
20+
ParseOk a -> return $ moduleCount a
21+
where -- the default fixities augmented with everything necessary to parse my corpus
22+
fixes :: [Fixity]
23+
fixes = baseFixities++[Fixity AssocRight 0 (VarOp (Symbol "==>"))]
24+
25+
functionSearch :: Module -> [Imports]
26+
functionSearch md = do undefined
27+
-- let x = length [ () | Var (UnQual (Ident a)) <- universeBi md, a == fun]

pager.hs

100755100644
File mode changed.

0 commit comments

Comments
 (0)