GHC as a library - getting output from GHCI
Simon Marlow
simonmarhaskell at gmail.com
Fri May 11 07:00:35 EDT 2007
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/ghc/
>> \____/\/ /_/\____/|_| Type :? for help.
>>
>> Loading package base ... linking ... done.
>> Prelude> :m + System.IO
>> Prelude System.IO> h <- openFile "out" WriteMode
>> {handle: out}
>> Prelude System.IO> GHC.Handle.hDuplicateTo h stdout
>> -- as this point, GHCi goes quiet: I type ":quit"
>> $ cat out
>> Prelude System.IO> :quit
>> Leaving GHCi.
>>
>> Cheers,
>> Simon
>
>
> Is there any way to create a handle which dumps its input into a
> string or memory buffer of some kind? I only know of the ability to
> open file/socket handles, and a quick browse of GHC/Handle.hs doesn't
> seem to indicate anything else. I'm not counting
> createPipe/fdToHandle because that is not portable.
Sadly not at the moment. Our Handle implementation is currently always backed
by a file descriptor. It would certainly be possible (though not easy) to
extend it in this direction.
Cheers,
Simon
More information about the Glasgow-haskell-users
mailing list