「ふ L」の次は「ふつける」らしい。そう来るとは思わなかった。
締め切りが本気で 23 日に確定。 あと 15 日だけど、そこまでに面接とかグループワークとかあるので毎日は書けない。 1 がものすごい勢いで原稿を書くスレ、的な状況になりそうだ。
(10:59)
よくよく考えると、Parsec を使ってしまってはあまり実装例にならない。 しょうがないので自分で実装する。
LineParser.hs
module LineParser
(LineParser, firstChar, indented, blank, anyLine,
parse, many, many1) where
import Parser
import Data.Char (isSpace)
type LineParser st a = Parser String a
firstChar :: (Char -> Bool) -> LineParser st String
firstChar f = satisfy (test f)
where
test f "" = False
test f (c:_) = f c
indented = firstChar isSpace
blank = satisfy (null . dropWhile isSpace)
anyLine = satisfy (const True)
Parser.hs
module Parser (Parser, parse, (<|>), satisfy, eof, many, many1) where
import Control.Monad
import Data.Either
import Data.Maybe
data Parser tok a = Parser ([tok] -> Maybe (a,[tok]))
parse :: Parser tok a -> [tok] -> Either String a
parse p input = case run p input of
Just (x, _) -> Right x
Nothing -> Left "parse error"
run :: Parser tok a -> [tok] -> Maybe (a,[tok])
run (Parser p) = p
instance Monad (Parser tok) where
return x = Parser (\state -> Just (x, state))
p >>= f = Parser (\state -> run p state >>= (\(x, st2) -> run (f x) st2))
fail msg = Parser (\state -> Nothing)
infixr 1 <|>
(<|>) :: Parser tok a -> Parser tok a -> Parser tok a
p1 <|> p2 = Parser f
where
f state = case run p1 state of
Just t -> Just t
Nothing -> run p2 state
satisfy :: (tok -> Bool) -> Parser tok tok
satisfy test = Parser nextState
where
nextState [] = Nothing
nextState (x:xs) | test x = Just (x, xs)
| otherwise = Nothing
eof :: Parser tok ()
eof = Parser nextState
where
nextState [] = Just ((), [])
nextState _ = Nothing
many :: Parser tok a -> Parser tok [a]
many p = do x <- p
xs <- many p
return (x:xs)
<|> return []
many1 :: Parser tok a -> Parser tok [a]
many1 p = do x <- p
xs <- many p
return (x:xs)
(11:43)
http://www.amazon.co.jp/exec/obidos/ASIN/4839919844
池袋を通ったので、そのついでに噂の 30 日で作れる本を買ってきた。 パラパラめくっただけだけど、これはおもしろそう。 野暮なツッコミはいろいろあるんだけど、野暮なので置いとく。
ていうか普通いきなりバイナリエディタでブートイメージを作らせようなんて考えねえよ! その勇気に脱帽した!
(11:44)