replacing guile with haskell?

Graham Klyne GK at
Tue Oct 21 14:47:51 EDT 2003

At 04:17 21/10/03 -0400, ajb at wrote:
>I think I might have mentioned this previously, but here's an interesting
>implementation of Knuth-Morris-Pratt substring searching (which is indeed
>a "little language") which illustrates something or other:

Nice.  Do you know if anyone has done anything like this for regular 
expressions?  I'm thinking in particular that a function that turned a 
regular expression into a Parsec parser function could be useful, as in:

    regexp.compile :: String -> GenParser Char st [String]

where GenParser is defined by the Parsec library [1], and the parsed result 
is a list of substrings corresponding to the (...) parts of the regexp (if 
matched, of course).  (The parser result type might warrant some refinement.)



ParsecPrim.hs defines GenParser thus:
-- Parser definition.
-- GenParser tok st a:
--  General parser for tokens of type "tok",
--  a user state "st" and a result type "a"
type Parser a           = GenParser Char () a

newtype GenParser tok st a  = Parser (State tok st -> Consumed (Reply tok 
st a))
runP (Parser p)             = p

data Consumed a         = Consumed a                --input is consumed
                         | Empty !a                  --no input is consumed

data Reply tok st a     = Ok !a !(State tok st) ParseError    --parsing 
succeeded with "a"
                         | Error ParseError                    --parsing failed

data State tok st       = State { stateInput :: ![tok]
                                 , statePos   :: !SourcePos
                                 , stateUser  :: !st

Graham Klyne
For email:

More information about the Haskell-Cafe mailing list