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

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

+39
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

+31
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

+113
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

+27
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.

searcher.hs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
-- import Debug.Trace
6+
7+
main :: IO ()
8+
main = do (func:_) <- getArgs
9+
args <- fmap lines $ getContents
10+
mapM_ (checkAndPrint func) args
11+
12+
checkAndPrint :: String -> FilePath -> IO ()
13+
checkAndPrint fn fs = do print fs
14+
x <- readFile fs
15+
let exts = F.concat $ readExtensions x
16+
let parsed = parseFileContentsWithMode (defaultParseMode { fixities = fixes, extensions = exts }) x
17+
case parsed of
18+
ParseFailed _ _ -> (return ())
19+
ParseOk a -> functionSearch fn a
20+
return ()
21+
22+
-- the default fixities augmented with everything necessary to parse my corpus
23+
fixes :: Maybe [Fixity]
24+
fixes = Just $ baseFixities ++ infixr_ 0 ["==>"]
25+
26+
functionSearch :: String -> Module -> IO ()
27+
functionSearch fun md = do
28+
let x = length [ () | Var (UnQual (Ident a)) <- universeBi md, a == fun]
29+
putStrLn $ "Found " ++ show x ++ " occurences of function " ++ fun

toogle.hs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{-
2+
write function-based search:
3+
Example code: `(find-fn 1 2 3) -> [clojure.add]`; `(+ 1 2) -> 3`
4+
but there are lots of `Int -> Int -> Int` functions! So it returns multiple results:
5+
it answers `2 2 4` with `[clojure.core/unchecked-multiply clojure.core/+ clojure.core/* clojure.core/unchecked-add]` (since 2*2=4 and 2+2=4)
6+
it searches based on the function running in a jailed environment for that reason
7+
in haskell: Lambdabot already does type inference, type searching, and safe evaluation, so your 1 2 3 example would go like split on whitespace, map a :t type-inferrer, run a Hoogle search on x -> y -> ... -> z, and evaluate using the first _n_ hits and print out all the ones that didn't error out up to _x_ successes
8+
-}
9+
import System.Environment
10+
11+
main = do args <- getArgs
12+
exprs <- mapM (\foo -> spawn $ "ghc -e \':type " ++ foo ++ " | tail -1")
13+
let paramtypes = map (drop 2 $ takeWhile (\x -> x /= ':')) exprs
14+
let ftype = concat $ intersperse " -> " paramtypes
15+
functions <- fmap lines $ spawn $ "hoogle '" ++ x ++ "'"
16+
eval functions (concat args)
17+
where eval :: [String] -> String -> IO ()
18+
eval (f:fs) args = do (status,res) <- spawn $ "mueval -e " ++ f ++ args
19+
case status of
20+
Succeeded -> print (f ++ " " ++ res)
21+
Failed -> eval fs args

wp-archivebot/Setup.lhs

-3
This file was deleted.

xosd-reminder.hs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import Graphics.XOSD
2+
import Control.Concurrent (threadDelay)
3+
import Data.Time.Clock (getCurrentTime)
4+
import Data.Time.Format (formatTime)
5+
import System.Locale (defaultTimeLocale)
6+
7+
main :: IO ()
8+
main = do threadDelay tenminutes
9+
time <- getCurrentTime
10+
let time' = formatTime defaultTimeLocale "%R" time
11+
runXOSD [ Timeout 2
12+
, VAlign VAlignTop
13+
, HAlign HAlignRight
14+
, Font "-*-dejavu sans mono-medium-r-*-*-17-*-*-*-*-*-*-*"
15+
, Color "LimeGreen"
16+
, Display (String time')]
17+
(const $ return ())
18+
main
19+
where second = 1000
20+
minute = second * 60
21+
tenminutes = 10 * minute
22+

0 commit comments

Comments
 (0)