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

Commit 51ed10b

Browse files
committed
import missing scripts
Ignore-this: 19b38d1fef5ab53c621485d19e0f539c darcs-hash:20090208011652-f7719-88b91d404a04ff772ebf6033d5c6fa3344391410
1 parent ff474c5 commit 51ed10b

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

add.hs

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{-
2+
3+
Here we have two examples of how we can define a abstract data type with a bunch
4+
of fields, serialize them to disk (using arbitrary Ints to represent each field)
5+
and then read them back in and restore the original list or whatevers of
6+
abstract data types.
7+
8+
The question is, how can we turn functions into data which can be serialized
9+
this way?
10+
-}
11+
{- http://hpaste.org/4265 -}
12+
{-
13+
module Main (main)
14+
where
15+
import Data.Binary
16+
data Math = Add | Subtract | Multiply
17+
deriving Show
18+
19+
eval :: (Num a) => Math -> a -> a -> a
20+
eval f = case f of
21+
Add -> (+)
22+
Subtract -> (-)
23+
Multiply -> (*)
24+
25+
instance Binary Math where
26+
put Add = putWord8 0
27+
put Subtract = putWord8 1
28+
put Multiply = putWord8 2
29+
get = do tag_ <- getWord8
30+
case tag_ of
31+
0 -> return Add
32+
1 -> return Subtract
33+
2 -> return Multiply
34+
35+
36+
main = do encodeFile "tmp.s" [Add, Subtract, Multiply]
37+
a <- decodeFile "tmp.s"
38+
putStr $ show (a :: [Math])
39+
-}
40+
41+
import Prelude hiding (reverse)
42+
import Data.Binary
43+
data STRING = Foldl | Flip | Colon | EmptyList
44+
deriving Show
45+
46+
-- eval :: (String a) => STRING -> a -> a -> a
47+
-- eval f = case f of
48+
-- Foldl -> (foldl1)
49+
-- Flip -> (flip)
50+
-- Colon -> (:)
51+
-- EmptyList -> ([])
52+
53+
54+
instance Binary STRING where
55+
put Foldl = putWord8 0
56+
put Flip = putWord8 1
57+
put Colon = putWord8 2
58+
put EmptyList = putWord8 3
59+
get = do tag_ <- getWord8
60+
case tag_ of
61+
0 -> return Foldl
62+
1 -> return Flip
63+
2 -> return Colon
64+
3 -> return EmptyList
65+
66+
main = do print [Foldl, Flip, Colon, EmptyList]
67+
encodeFile "tmp.s" [Foldl, Flip, Colon, EmptyList]
68+
a <- decodeFile "tmp.s"
69+
print (a :: [STRING])
70+
71+
-- foldl $ flip (:) []

fdupe.hs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Split (split)
2+
import Control.Monad (liftM)
3+
4+
main :: IO ()
5+
main = do arg <- liftM (concat . map (fun . lines) . breakBlankLines) $ getContents
6+
mapM_ putStrLn arg
7+
8+
breakBlankLines :: String -> [String]
9+
breakBlankLines = map (\x -> if head x == '\n' then tail x else x) . filter (not . (==) "") . map concat . split (=="") . split (=='\n')
10+
11+
fun :: [String] -> [String]
12+
fun strs = map (\x -> "ln -sf " ++ "\'" ++ (head strs) ++ "\' " ++ "\'" ++ x ++ "\'") $ tail strs

tmr.hs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import Text.HTML.TagSoup.Render
2+
import Text.HTML.TagSoup
3+
4+
main :: IO ()
5+
main = interact convertPre
6+
7+
convertPre :: String -> String
8+
convertPre = renderNoQuoting . map convertToHaskell . canonicalizeTags . parseTags
9+
where renderNoQuoting = renderTagsOptions (renderOptions{optEscape = (:[])})
10+
11+
convertToHaskell :: Tag -> Tag
12+
convertToHaskell (TagOpen "pre" atts) = TagOpen "haskell" atts
13+
convertToHaskell (TagClose "pre") = TagClose "haskell"
14+
convertToHaskell x = x
15+
16+
{- Parsec version from John MacFarlane:
17+
18+
import Text.ParserCombinators.Parsec
19+
20+
pPreHaskell = try $ do
21+
string "<pre class=\"haskell\">"
22+
body <- manyTill anyChar (try $ string "</pre>")
23+
return $ "<haskell>" ++ body ++ "</haskell>"
24+
25+
pOther = many (noneOf "<") <|> string "<"
26+
27+
pDoc = many (pPreHaskell <|> pOther) >>= return . concat
28+
29+
main = do
30+
c <- getContents
31+
case parse pDoc "" c of
32+
Left err -> error $ show err
33+
Right res -> putStrLn res
34+
-}

uniq.hs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module Main where
2+
import Control.Monad
3+
import Data.List
4+
import qualified Data.Set as Set
5+
6+
main :: IO ()
7+
main = do files <- (liftM ((\h -> map (!!1) $ Set.toList $ Set.difference (Set.fromList $ i h) (j h))) $ getContents)
8+
mapM_ (\x -> putStrLn $ "rm -f \'" ++ x ++ "\'") files
9+
where i = map words . sort . lines
10+
j = Set.fromList . nubBy (\x y -> head x == head y) . i

0 commit comments

Comments
 (0)