|
import Parser |
|
|
|
= three |
|
{- Inline three -} |
|
= pure g <*> item <*> item <*> item |
|
{- Inline (pure g) -} |
|
= P (\inp -> [(g, inp)]) <*> item <*> item <*> item |
|
{- Inline (P ... <*> item) -} |
|
= P (\inp -> case parse (P (\inp1 -> [(g, inp1)])) inp of |
|
[] -> [] |
|
[(g1, out)] -> parse (fmap g1 item) out) <*> item <*> item |
|
{- Inline (parse (P ...))-} |
|
= P (\inp -> case (\inp1 -> [(g, inp1)]) inp of |
|
[] -> [] |
|
[(g1, out)] -> parse (fmap g1 item) out) <*> item <*> item |
|
{- Beta ((\inp1 -> ...) inp) -} |
|
= P (\inp -> case [(g, inp)] of |
|
[] -> [] |
|
[(g1, out)] -> parse (fmap g1 item) out) <*> item <*> item |
|
{- Evaluate case -} |
|
= P (\inp -> parse (fmap g item) inp) <*> item <*> item |
|
{- Inline (fmap g item) -} |
|
= P (\inp -> parse (P (\inp1 -> case parse item inp1 of |
|
[] -> [] |
|
[(v, out)] -> [(g v, out)])) inp) <*> item <*> item |
|
{- Inline (parse (P ...))-} |
|
= P (\inp -> (\inp1 -> case parse item inp1 of |
|
[] -> [] |
|
[(v, out)] -> [(g v, out)]) inp) <*> item <*> item |
|
{- Beta ((\inp1 -> ...) inp) -} |
|
= P (\inp -> case parse item inp of |
|
[] -> [] |
|
[(v, out)] -> [(g v, out)]) <*> item <*> item |
|
{- Inline item -} |
|
= P (\inp -> case parse (P (\inp1 -> case inp1 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)])) inp of |
|
[] -> [] |
|
[(v, out)] -> [(g v, out)]) <*> item <*> item |
|
{- Inline (parse (P ...))-} |
|
{- Beta ((\inp1 -> ...) inp) -} |
|
= P (\inp -> case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out)] -> [(g v, out)]) <*> item <*> item |
|
{- Inline (P ... <*> item) -} |
|
= P (\inp -> case parse (P (\inp1 -> case (case inp1 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)])) inp of |
|
[] -> [] |
|
[(g1, out)] -> parse (fmap g1 item) out) <*> item |
|
{- Inline (parse (P ...))-} |
|
{- Beta ((\inp1 -> ...) inp) -} |
|
= P (\inp -> case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> parse (fmap g1 item) out) <*> item |
|
{- Inline (fmap g1 item) -} |
|
= P (\inp -> case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> parse (P (\inp1 -> case parse item inp1 of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)])) out) <*> item |
|
{- Inline (parse (P ...)) -} |
|
{- Beta ((\inp1 -> ...) out) -} |
|
= P (\inp -> case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case parse item out of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) <*> item |
|
{- Inline item -} |
|
= P (\inp -> case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case parse (P (\inp1 -> case inp1 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)])) out of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) <*> item |
|
{- Inline (parse (P ...)) -} |
|
{- Beta ((\inp1 -> ...) out) -} |
|
= P (\inp -> case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) <*> item |
|
{- Inline (P ... <*> item) -} |
|
= P (\inp -> case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) <*> item |
|
= P (\inp -> case parse (P (\inp1 -> case (case (case inp1 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)])) inp of |
|
[] -> [] |
|
[(g2, out3)] -> parse (fmap g2 item) out3) |
|
{- Inline (parse (P ...)) -} |
|
{- Beta ((\inp1 -> ...) inp) -} |
|
= P (\inp -> case (case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> parse (fmap g2 item) out3) |
|
{- Inline (fmap g2 item) -} |
|
= P (\inp -> case (case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> parse (P (\inp1 -> case parse item inp1 of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)])) out3) |
|
{- Inline (parse (P ...)) -} |
|
{- Beta ((\inp1 -> ...) out3) -} |
|
= P (\inp -> case (case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> case parse item out3 of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)]) |
|
{- Inline item -} |
|
= P (\inp -> case (case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> case parse (P (\inp1 -> case inp1 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)])) out3 of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)]) |
|
{- Inline (parse (P ...)) -} |
|
{- Beta ((\inp1 -> ...) out3) -} |
|
= P (\inp -> case (case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> case (case out3 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)]) |
|
|
|
#threeSteps |
|
|
|
---------------------------------------------------------------------- |
|
|
|
= parse three ('a' : 'b' : 'c' : []) |
|
{- By above -} |
|
= parse (P (\inp -> case (case (case (case inp of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> case (case out3 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)])) ('a' : 'b' : 'c' : []) |
|
{- Inline (parse (P ...)) -} |
|
{- Beta ((\inp -> ...) ('a' : ...)) -} |
|
= case (case (case (case ('a' : 'b' : 'c' : []) of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> case (case out3 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)] |
|
{- Evaluate case -} |
|
= case (case (case [('a', 'b' : 'c' : [])] of |
|
[] -> [] |
|
[(v, out1)] -> [(g v, out1)]) of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> case (case out3 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)] |
|
{- Evaluate case -} |
|
= case (case [(g 'a', 'b' : 'c' : [])] of |
|
[] -> [] |
|
[(g1, out)] -> case (case out of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g1 v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> case (case out3 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)] |
|
{- Evaluate case -} |
|
= case (case (case ('b' : 'c' : []) of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out2)] -> [(g 'a' v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> case (case out3 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)] |
|
{- Evaluate case -} |
|
= case (case [('b', 'c' : [])] of |
|
[] -> [] |
|
[(v, out2)] -> [(g 'a' v, out2)]) of |
|
[] -> [] |
|
[(g2, out3)] -> case (case out3 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)] |
|
{- Evaluate case -} |
|
= case [(g 'a' 'b', 'c' : [])] of |
|
[] -> [] |
|
[(g2, out3)] -> case (case out3 of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out4)] -> [(g2 v, out4)] |
|
{- Evaluate case -} |
|
= case (case ('c' : []) of |
|
[] -> [] |
|
(x:xs) -> [(x, xs)]) of |
|
[] -> [] |
|
[(v, out4)] -> [(g 'a' 'b' v, out4)] |
|
{- Evaluate case -} |
|
= case [('c', [])] of |
|
[] -> [] |
|
[(v, out4)] -> [(g 'a' 'b' v, out4)] |
|
{- Evaluate case -} |
|
= [(g 'a' 'b' 'c', [])] |
|
{- Inline (g 'a' 'b' 'c')-} |
|
= [(('a', 'c'), [])] |
|
|
|
#parsedSteps |
|
|
|
main = do |
|
let result = [(('a','c'),"")] |
|
check1 = all (\x -> parse x "abc" == result) threeSteps |
|
check2 = all (== result) parsedSteps |
|
if check1 && check2 |
|
then putStrLn "OK" |
|
else putStrLn "Not OK!" |