diff options
Diffstat (limited to 'testsuite/tests/simplCore/prog002/Simpl009Help.hs')
-rw-r--r-- | testsuite/tests/simplCore/prog002/Simpl009Help.hs | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/testsuite/tests/simplCore/prog002/Simpl009Help.hs b/testsuite/tests/simplCore/prog002/Simpl009Help.hs new file mode 100644 index 0000000000..ac75943016 --- /dev/null +++ b/testsuite/tests/simplCore/prog002/Simpl009Help.hs @@ -0,0 +1,39 @@ +{-# LANGUAGE ScopedTypeVariables, RankNTypes #-} + +-- Helper for simpl009.hs (see comments there) + +module Simpl009Help where + +import Control.Monad + +newtype Parser s a + = Parser (forall res . (a -> [String] -> P s res) -> [String] -> P s res) + +data P s res + = Symbol (s -> P s res) + | Fail [String] [String] + | Result res (P s res) + +instance Monad (Parser s) where + return a = Parser (\fut -> fut a) + + Parser f >>= k = + Parser (\fut -> f (\a -> let Parser g = k a in g fut)) + + fail s = + Parser (\fut exp -> Fail exp [s]) + +instance MonadPlus (Parser s) where + mplus = error "urk" + mzero = Parser (\fut exp -> Fail exp []) + +lookAhead :: forall s. Parser s s +lookAhead = + Parser (\fut exp -> Symbol (\c -> + feed c (fut c []) + )) + where + feed :: forall res. s -> P s res -> P s res + feed c (Symbol sym) = sym c + feed c (Result res fut) = Result res (feed c fut) + feed c p@(Fail _ _) = p |