Re: [Haskell-cafe] IO within parser
Malte Milatz wrote: Sam Hughes [EMAIL PROTECTED], Sun, 12 Aug 2007 20:12:55 -0400: [A parser like Parsec, with monad transformers:] $ darcs get http://samuelhughes.com/darcs/partran/ Is this related in any way to the following GSoC project? http://code.google.com/soc/2007/haskell/appinfo.html?csaid=B97EF4562EF3B244 No, I just wanted it for my own purposes. - Sam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Fw: [Haskell-cafe] IO within parser
Hello Gregory, Sunday, August 12, 2007, 9:32:04 AM, you wrote: I've been struggling with writing a parser that needs to parse include files within source files. Parsec can't accomplish with without using unsafePerformIO because it's monad is pure. it's algorithmically impossible to have any i/o actions inside it. there was plans to rewrite Parsec in monad-transformer way and afair it was even one of GSOC projects -- Best regards, Bulatmailto:[EMAIL PROTECTED] ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] IO within parser
Gregory Propf, Sat, 11 Aug 2007 13:06:43 -0700: but the type of liftIO is baffling class Monad m = MonadIO m where liftIO :: IO a - m a But how do you define this function? There is no constructor for IO a that you can take apart. If not using unsafePerformIO, which is usually not what we want, the monad m in question must incorporate IO. That is, it could be defined something like (say we want a parser with state): newtype IOParser tok s a = IOParser (s - [tok] - IO (s,a)) You can then define liftIO without “taking apart” the IO value; instead you put liftIO's IO action (IO a) into IOParser's IO action (IO (s,a)). Parsec does not define any such parser, though, so there's nothing for which you may define an instance of MonadIO. Malte ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: Fw: [Haskell-cafe] IO within parser
I noticed that StateT can enclose IO actions for instance. So you are saying the whole Parsec library would need to be rewritten as something like a ParsecT transformer monad for this to work? If this is the case I suppose I will stick with returning my list of include files. - Greg - Original Message From: Bulat Ziganshin [EMAIL PROTECTED] To: Gregory Propf [EMAIL PROTECTED] Cc: haskell-cafe@haskell.org Sent: Saturday, August 11, 2007 11:33:00 PM Subject: Re: Fw: [Haskell-cafe] IO within parser Hello Gregory, Sunday, August 12, 2007, 9:32:04 AM, you wrote: I've been struggling with writing a parser that needs to parse include files within source files. Parsec can't accomplish with without using unsafePerformIO because it's monad is pure. it's algorithmically impossible to have any i/o actions inside it. there was plans to rewrite Parsec in monad-transformer way and afair it was even one of GSOC projects -- Best regards, Bulatmailto:[EMAIL PROTECTED] Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] IO within parser
Malte Milatz wrote: If not using unsafePerformIO, which is usually not what we want, the monad m in question must incorporate IO. That is, it could be defined something like (say we want a parser with state): newtype IOParser tok s a = IOParser (s - [tok] - IO (s,a)) You can then define liftIO without “taking apart” the IO value; instead you put liftIO's IO action (IO a) into IOParser's IO action (IO (s,a)). Parsec does not define any such parser, though, so there's nothing for which you may define an instance of MonadIO. Malte I'm making (or have made) such a thing, although not necessarily atop IO, atop any monad that provides certain stream-like functionality. It's kind of done, but not really. $ darcs get http://samuelhughes.com/darcs/partran/ That is virtually completely untested and has not been proven correct either. Also, whatever documentation there is has probably accidentally been copied and pasted from Parsec's (except for the documentation of Stream.hs). Some of the unthinkingly done translations of the files found in Parsec's hierarchy seem to be idiomatically immoral. (Token.hs comes to mind. Something went wrong with functional dependencies and avoiding things like breaking the coverage condition/undecidable instances and it hurts. Maybe somebody could tell me what I'm doing wrong.) Also, some functions and definitions of things might be appropriately moved around, and you'll probably end up having to import more than you'd like to. Text.ParserCombinators.ParTran.Parsec /might/ currently contain a correct simulation of Text.ParserCombinators.Parsec. - Sam ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] IO within parser
I've been struggling with writing a parser that needs to parse include files within source files. So far I cannot get this to work (in reality to get work done I wrote a kludge that returns a list of include filenames to be run later in a pure IO function. I realized that this just amounted to creating my own half-assed monad system so I really don't want to use this approach). I have read the tutorials I could find on monad transformers but I still don't see what's going on. I'm using the Parsec parser library. Here's an simple example of what I've tried. I also tried using liftIO and got a message about needing to add an instance of MonadIO. This made more sense but the type of liftIO is baffling class Monad m = MonadIO m where liftIO :: IO a - m a But how do you define this function? There is no constructor for IO a that you can take apart. Anyway, here is the code that just uses lift. Keep in mind that the outer monad is just GenParser Char st [Char]. I'm guessing this is wrong and I should have a transformer monad as the outer layer. But which one? and how to use it? pio = do { s - many1 alphaNum; input - lift (readFile s); return input; } go6 = runParser pio () This is a test = ghc output from trying to load this is = Couldn't match kind `* - * - *' against `(* - *) - * - *' When matching the kinds of `GenParser Char :: * - * - *' and `t :: (* - *) - * - *' Expected type: GenParser Char st Inferred type: t IO In a 'do' expression: lift (writeFile Foo s) Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us. http://surveylink.yahoo.com/gmrs/yahoo_panel_invite.asp?a=7 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] IO within parser
Gregory Propf wrote: I've been struggling with writing a parser that needs to parse include files within source files. So far I cannot get this to work (in reality to get work done I wrote a kludge that returns a list of include filenames to be run later in a pure IO function. I realized that this just amounted to creating my own half-assed monad system so I really don't want to use this approach). I have read the tutorials I could find on monad transformers but I still don't see what's going on. I'm using the Parsec parser library. Here's an simple example of what I've tried. I also tried using liftIO and got a message about needing to add an instance of MonadIO. This made more sense but the type of liftIO is baffling The fun part is that Parsec already has a feature for include files... (I can't remember where the heck it is or how you use it though.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Fw: [Haskell-cafe] IO within parser
Well the docs ( http://legacy.cs.uu.nl/daan/download/parsec/parsec.html ) hint that setInput and getInput are good for this. I can certainly how they *would* be - if I knew how to pull in files within the parse. Actually I use those functions to do multiple recursive passes but of course you already have the output from the first pass in the parser there. runParser only *looks* like it takes input from a file. Actually it just parses the string you give it and uses the filename arg for error messages only. You still need a way to pull the data into the string from the file. (Note: I accidentally sent this to Andrew instead of the list originally) - Original Message From: Andrew Coppin [EMAIL PROTECTED] To: haskell-cafe@haskell.org Sent: Saturday, August 11, 2007 1:25:16 PM Subject: Re: [Haskell-cafe] IO within parser Gregory Propf wrote: I've been struggling with writing a parser that needs to parse include files within source files. So far I cannot get this to work (in reality to get work done I wrote a kludge that returns a list of include filenames to be run later in a pure IO function. I realized that this just amounted to creating my own half-assed monad system so I really don't want to use this approach). I have read the tutorials I could find on monad transformers but I still don't see what's going on. I'm using the Parsec parser library. Here's an simple example of what I've tried. I also tried using liftIO and got a message about needing to add an instance of MonadIO. This made more sense but the type of liftIO is baffling The fun part is that Parsec already has a feature for include files... (I can't remember where the heck it is or how you use it though.) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe Fussy? Opinionated? Impossible to please? Perfect. Join Yahoo!'s user panel and lay it on us. Choose the right car based on your needs. Check out Yahoo! Autos new Car Finder tool. http://autos.yahoo.com/carfinder/___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe