module Yi.Syntax where
import Control.Arrow( first )
data Color = Red | Black deriving (Eq)
data MayFail
data MustSucceed
data Parser p where
Fail :: Parser MayFail
Cont :: [Color] -> (Char -> Parser p) -> Parser p
run :: Parser MustSucceed -> ([Color], Char -> Parser MustSucceed)
run (Cont a b) = (a, b)
(</>) :: Parser MayFail -> Parser p -> Parser p
Fail </> x = x
x </> Fail = x
Cont r1 c1 </> Cont r2 c2 = Cont rc (\ch -> telling rs1 (c1 ch) </> telling rs2 (c2 ch))
where
(rc, (rs1, rs2)) = common r1 r2
common (x:xs) (y:ys) | x == y = first (x:) (common xs ys)
common xl yl = ([], (xl,yl))
telling :: [Color] -> Parser p -> Parser p
telling ls Fail = Fail
telling ls (Cont r c) = Cont (ls ++ r) c
-+ Errors (1)
`
against inferred type `p' (a rigid variable)
`p' is bound by the type signature for `</>'
at /home/stefan/synhllib/Yi/Syntax.hs:17:34
Expected type: Parser MayFail
Inferred type: Parser p
In the second argument of `telling', namely `(c2 ch)'
In the second argument of `(</>)', namely `telling rs2 (c2 ch)'
[+] Infos (1)