FS

Blog Archive

Tuesday, July 03, 2007

Hurrah for fixed points


import System.IO

-- My first haskell quine, revised

main :: IO ()
main = do (putStr . map toEnum) prog

(putStr . breaker . show) prog

putStr "\n"

breaker :: String -> String
breaker = (unwordsBy ',' . f . wordsBy ',') where
f xs
| length xs > 8 = (take 8 xs) ++ (f . g) (drop 8 xs)
| otherwise = xs

g [] = []
g (x:xs) = ("\n " ++ x):xs

-- Adapted from "lines" in the GHC List module
wordsBy :: Char -> String -> [String]
wordsBy _ "" = []
wordsBy c s = let (l, s') = break (== c) s in
l: case s' of
[] -> []
(_:s'') -> wordsBy c s''

-- Adapted from "unlines" in the GHC List module
unwordsBy :: Char -> [String] -> String
unwordsBy _ [] = ""
unwordsBy c ws = foldr1 (\w s -> w ++ c:s) ws

prog :: [Int]
prog = [105,109,112,111,114,116,32,83,
121,115,116,101,109,46,73,79,
10,10,45,45,32,77,121,32,
102,105,114,115,116,32,104,97,
115,107,101,108,108,32,113,117,
105,110,101,44,32,114,101,118,
105,115,101,100,10,10,109,97,
105,110,32,58,58,32,73,79,
32,40,41,10,109,97,105,110,
32,61,32,100,111,32,40,112,
117,116,83,116,114,32,46,32,
109,97,112,32,116,111,69,110,
117,109,41,32,112,114,111,103,
10,10,32,32,32,32,32,32,
32,32,32,32,40,112,117,116,
83,116,114,32,46,32,98,114,
101,97,107,101,114,32,46,32,
32,115,104,111,119,41,32,112,
114,111,103,10,10,32,32,32,
32,32,32,32,32,32,32,112,
117,116,83,116,114,32,34,92,
110,34,10,10,98,114,101,97,
107,101,114,32,58,58,32,83,
116,114,105,110,103,32,45,62,
32,83,116,114,105,110,103,10,
98,114,101,97,107,101,114,32,
61,32,40,117,110,119,111,114,
100,115,66,121,32,39,44,39,
32,46,32,102,32,46,32,119,
111,114,100,115,66,121,32,39,
44,39,41,32,119,104,101,114,
101,10,32,32,102,32,120,115,
10,32,32,32,32,124,32,108,
101,110,103,116,104,32,120,115,
32,62,32,56,32,61,32,40,
116,97,107,101,32,56,32,120,
115,41,32,43,43,32,40,102,
32,46,32,103,41,32,40,100,
114,111,112,32,56,32,120,115,
41,10,32,32,32,32,124,32,
111,116,104,101,114,119,105,115,
101,32,32,32,32,32,61,32,
120,115,10,10,32,32,103,32,
32,91,93,32,32,32,32,61,
32,91,93,10,32,32,103,32,
40,120,58,120,115,41,32,61,
32,40,34,92,110,32,34,32,
43,43,32,120,41,58,120,115,
32,10,10,45,45,32,65,100,
97,112,116,101,100,32,102,114,
111,109,32,34,108,105,110,101,
115,34,32,105,110,32,116,104,
101,32,71,72,67,32,76,105,
115,116,32,109,111,100,117,108,
101,10,119,111,114,100,115,66,
121,32,58,58,32,67,104,97,
114,32,45,62,32,83,116,114,
105,110,103,32,45,62,32,91,
83,116,114,105,110,103,93,10,
119,111,114,100,115,66,121,32,
95,32,34,34,32,61,32,91,
93,10,119,111,114,100,115,66,
121,32,99,32,115,32,32,61,
32,108,101,116,32,40,108,44,
32,115,39,41,32,61,32,98,
114,101,97,107,32,40,61,61,
32,99,41,32,115,32,105,110,
10,32,32,32,32,32,32,32,
32,32,32,32,32,32,32,32,
108,58,32,99,97,115,101,32,
115,39,32,111,102,10,32,32,
32,32,32,32,32,32,32,32,
32,32,32,32,32,32,32,32,
32,32,91,93,32,32,32,32,
32,32,45,62,32,91,93,10,
32,32,32,32,32,32,32,32,
32,32,32,32,32,32,32,32,
32,32,32,32,40,95,58,115,
39,39,41,32,45,62,32,119,
111,114,100,115,66,121,32,99,
32,115,39,39,10,10,45,45,
32,65,100,97,112,116,101,100,
32,102,114,111,109,32,34,117,
110,108,105,110,101,115,34,32,
105,110,32,116,104,101,32,71,
72,67,32,76,105,115,116,32,
109,111,100,117,108,101,10,117,
110,119,111,114,100,115,66,121,
32,58,58,32,67,104,97,114,
32,45,62,32,91,83,116,114,
105,110,103,93,32,45,62,32,
83,116,114,105,110,103,10,117,
110,119,111,114,100,115,66,121,
32,95,32,91,93,32,61,32,
34,34,10,117,110,119,111,114,
100,115,66,121,32,99,32,119,
115,32,61,32,102,111,108,100,
114,49,32,40,92,119,32,115,
32,45,62,32,119,32,43,43,
32,99,58,115,41,32,119,115,
10,10,112,114,111,103,32,58,
58,32,91,73,110,116,93,10,
112,114,111,103,32,61,32]

No comments:

Listening:

Watching:

  • House
  • Ride Back