--- /dev/null
+definition module yard
+
+from Data.Either import :: Either
+from StdClass import class Eq
+from Data.Functor import class Functor
+from Control.Monad import class Monad
+from Control.Applicative import class Applicative, class Alternative
+
+:: Parser a b = Parser ([a] -> (Either Error b, [a]))
+:: Error = ParseException
+
+runParser :: (Parser a b) [a] -> (Either Error b, [a])
+
+instance Functor (Parser a)
+instance Applicative (Parser a)
+instance Monad (Parser a)
+instance Alternative (Parser a)
+
+fail :: Parser a b
+top :: Parser a a
+satisfy :: (a -> Bool) -> Parser a a
+item :: a -> Parser a a | Eq a
+list :: [a] -> Parser a [a] | Eq a
\ No newline at end of file
--- /dev/null
+implementation module yard
+
+import StdTuple
+from StdClass import Eq
+import Data.Functor
+import Control.Monad
+import Control.Applicative
+from Data.Func import $
+
+runParser :: (Parser a b) [a] -> (Either Error b, [a])
+runParser (Parser f) i = f i
+
+instance Functor (Parser a) where
+ //fmap f m = liftM f m
+ fmap g p = Parser \i -> case runParser p i of
+ (Right r, rest) = (Right $ g r, rest)
+ (Left e, rest) = (Left e, rest)
+
+instance Applicative (Parser a) where
+ pure a = Parser \i -> (Right a, i)
+ //(<*>) sf p = ap sf p
+ (<*>) pf p = Parser \i -> case runParser pf i of
+ (Right f, rest) = runParser (fmap f p) rest
+ (Left e, rest) = (Left e, rest)
+
+instance Monad (Parser a) where
+ bind p f = Parser \i -> case runParser p i of
+ (Right r, rest) = runParser (f r) rest
+ (Left e, rest) = (Left e, rest)
+
+//some, many, optional and l
+instance Alternative (Parser a) where
+ empty = Parser \i -> (Left ParseException, i)
+ (<|>) p1 p2 = Parser \i -> case runParser p1 i of
+ (Right r, rest) = (Right r, rest)
+ (Left _, rest) = runParser p2 i
+
+fail :: Parser a b
+fail = empty
+
+top :: Parser a a
+top = Parser \i -> case i of
+ [] = (Left ParseException, [])
+ [x:xs] = (Right x, xs)
+
+satisfy :: (a -> Bool) -> Parser a a
+satisfy f = one >>= \r -> if (f r) (return r) fail
+
+item :: a -> Parser a a | Eq a
+item a = satisfy ((==)a)
+
+list :: [a] -> Parser a [a] | Eq a
+list as = mapM item as
\ No newline at end of file