Re: "GHC as a library" stalls when nobody is consuming it's output

2007-06-08 Thread Simon Marlow
Mads Lindstrøm wrote: While trying to implement a GUI for GHCi, I have run into an annoying concurrency problems. I think "GHC as a library" is at fault, as it stalls (maybe some deadlock) when nobody is consuming it's output. Thanks Mads, I took a look but didn't get to the bottom of the prob

Re: GHC as a library

2007-05-31 Thread Simon Marlow
Simon Peyton-Jones wrote: | In typecheckedSource, I can only access the function definitions with | type annotations, but not the data type declaration. | In checkedModuleInfo, I can only access the "Names" of the exported | entities, and but not their (inferred) types are not present. You have

RE: GHC as a library

2007-05-30 Thread Simon Peyton-Jones
| In typecheckedSource, I can only access the function definitions with | type annotations, but not the data type declaration. | In checkedModuleInfo, I can only access the "Names" of the exported | entities, and but not their (inferred) types are not present. You have easy access to the data decl

Re: GHC as a library - getting output from GHCI

2007-05-11 Thread Simon Marlow
Matthew Danish wrote: On Thu, May 10, 2007 at 09:34:53AM +0100, Simon Marlow wrote: And we do have support for this in GHC. $ ghci ___ ___ _ / _ \ /\ /\/ __(_) / /_\// /_/ / / | |GHC Interactive, version 6.7, for Haskell 98. / /_\\/ __ / /___| |http://www.haskell.org/gh

Re: GHC as a library - getting output from GHCI

2007-05-10 Thread Matthew Danish
On Thu, May 10, 2007 at 09:34:53AM +0100, Simon Marlow wrote: > And we do have support for this in GHC. > > $ ghci >___ ___ _ > / _ \ /\ /\/ __(_) > / /_\// /_/ / / | |GHC Interactive, version 6.7, for Haskell 98. > / /_\\/ __ / /___| |http://www.haskell.org/ghc/ > \/

Re: GHC as a library - getting output from GHCI

2007-05-10 Thread Simon Marlow
Simon Peyton-Jones wrote: | Also if stmt = | | SomeModule.prettyPrinter "foobar" | | and SomeModule contains | | prettyPrinter x = putStrLn $ "Pretty: " ++ x | | then the let binding will not catch it. Indeed, that's exactly what I meant in my original msg. I have always thought it ugly

RE: GHC as a library - getting output from GHCI

2007-05-10 Thread Simon Peyton-Jones
| Also if stmt = | | SomeModule.prettyPrinter "foobar" | | and SomeModule contains | | prettyPrinter x = putStrLn $ "Pretty: " ++ x | | then the let binding will not catch it. Indeed, that's exactly what I meant in my original msg. I have always thought it ugly that stdin and stdout are t

Re: GHC as a library - getting output from GHCI

2007-05-09 Thread Mads Lindstrøm
Hi While wrapIO works in most cases, try running this: :m +Control.Concurrent forkIO (let foo = do threadDelay 100; print "A"; foo in foo) I am not saying that this makes wrapIO unusable - just that it is not bulletproof. If not using forkIO is ok, then this is a much easier solution, than c

Re: GHC as a library - getting output from GHCI

2007-05-09 Thread Matthew Danish
On Wed, May 09, 2007 at 10:48:15PM +0200, Mads Lindstr?m wrote: > Hi > > Look at System.Posix.IO > > I do not know if that module can do what you want. But it does deal with > FileDescriptors and handles. > > Maybe the dup function can help you. According to > http://www2.lib.uchicago.edu/~keith

RE: GHC as a library - getting output from GHCI

2007-05-09 Thread Mads Lindstrøm
Hi Simon The Interactive.hs program do not really redirect stdout. It intercepts calls to putStrLn and getLine via let definitions: mustWork "let putStrLn = MyPrelude.myPutStrLn" mustWork "let getLine = MyPrelude.myGetLine" -- mustWork either runs the given statement successfull

Re: GHC as a library - getting output from GHCI

2007-05-09 Thread Mads Lindstrøm
Hi Look at System.Posix.IO I do not know if that module can do what you want. But it does deal with FileDescriptors and handles. Maybe the dup function can help you. According to http://www2.lib.uchicago.edu/~keith//tcl-course/topics/processes.html it does: "The dup implements the dup system ca

Re: GHC as a library - getting output from GHCI

2007-05-09 Thread Matthew Danish
On Fri, May 04, 2007 at 08:12:55PM +0200, Pepe Iborra wrote: > Mads > > On 04/05/2007, at 19:19, Mads Lindstr?m wrote: > > >Hi Pepe > > > >I would have liked something cross-platform. > > > > Take a look at the unix-compat[1] package by Bjorn Bringert, although > it looks like it won't help yo

RE: GHC as a library - getting output from GHCI

2007-05-07 Thread Simon Peyton-Jones
| I am trying to use GHC as a library (see | http://haskell.org/haskellwiki/GHC/As_a_library ). I want to get all the | output from an interactive session and put in a GUI. This | http://haskell.org/sitewiki/images/5/51/Interactive.hs seemed to be a | nice starting point. If you want to collect *a

Re: GHC as a library - getting output from GHCI

2007-05-06 Thread Mads Lindstrøm
Hi Pepe Pepe Iborra wrote: > Mads > > On 04/05/2007, at 19:19, Mads Lindstrøm wrote: > > > Hi Pepe > > > > > > I would have liked something cross-platform. > > > > > > > Take a look at the unix-compat[1] package by Bjorn Bringert, although > it looks like it won't help you. Maybe it can be

Re: GHC as a library - getting output from GHCI

2007-05-04 Thread Pepe Iborra
Mads On 04/05/2007, at 19:19, Mads Lindstrøm wrote: Hi Pepe I would have liked something cross-platform. Take a look at the unix-compat[1] package by Bjorn Bringert, although it looks like it won't help you. Maybe it can be extended. Also, if stmt contains an error, wrapStmt will not be

Re: GHC as a library - getting output from GHCI

2007-05-04 Thread Mads Lindstrøm
Hi Pepe I would have liked something cross-platform. Also, if stmt contains an error, wrapStmt will not be evaluated, and the resulting error is written to standard output or maybe to standard error. Whichever way, I am back to the same problem. Greetings, Mads Lindstrøm > I believe that the

Re: GHC as a library - getting output from GHCI

2007-05-04 Thread Pepe Iborra
I believe that the trick is to wrap your stmt in a IO handler that captures stdout and returns it together with the value of your stmt. That is, something with a type: wrapStmt :: IO a -> IO (a,String) It should be easy to implement wrapStmt using System.Posix.Process. Then you just define