GHC as a library - getting output from GHCI
Matthew Danish
mdanish at andrew.cmu.edu
Thu May 10 14:38:05 EDT 2007
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.
--
-- Matthew Danish -- user: mrd domain: cmu.edu
-- OpenPGP public key: C24B6010 on keyring.debian.org
More information about the Glasgow-haskell-users
mailing list