Communicating with other programs (Win32)
Hi all, In my free time, I'm writing a Go program in Haskell. Main platform is GHC and GHCi under Win32. It is coming along nicely: it has a GUI and the moves it comes up with are starting to make some sense. For testing (and maybe later training :) purposes I want it to be able to play against GnuGo (the strongest Open Source Go program) on its own. Currently, to get GnuGo to think up a move, I use something like (SGF is the standard way of outputting Go games): | do writeFile "in.sgf" (showAsSGF game) |let cmd = "echo quit > gnugo --quiet --infile in.sgf --color " ++ | (show computerColor) ++ | " --mode ascii > out.txt" |system cmd |result <- readFile "out.txt" |return (parseResultMove result) I think this both ugly and inefficient: for every move a new instance of GnuGo gets started and an SGF file is output! Instead, I want to start GnuGo only once per game and communicate with it like a human player would, by typing commands at it; or by using the Go Text Protocol which is specifically designed for computer-computer play. Does anybody here know a way - under Win32 - to start a process in the background and communicate with it via its stdin/stdout? I've poked around a bit in the Win32 library source, looking for an FFI interface to CreateProcess (the API function which does what I want) but found nothing. The Posix library looks like it should be up to the job, but unfortunately that isn't supported under Win32... (I'm not using Cygwin) Any help would be appreciated! Cheers, Jan de Wit ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Casting dynamic values
27 Nov 2001 17:31:10 -0700, Alastair David Reid <[EMAIL PROTECTED]> pisze: > If GHC is able to inline these functions, construction and > deconstruction of the pair can probably be eliminated. cast is compiled to something similar to this: coerce :: a -> b -- this generates no runtime code type Typeable a = a -> TypeRep cast :: Typeable a -> Typeable b -> a -> Maybe b cast t1 t2 x = case t1 x of rep1 -> case t2 (coerce x) of rep2 -> case eqTypeRep rep1 rep2 of True -> Just (coerce x) False -> Nothing Instances of Typeable should not look at their argument to determine TypeRep of its type but unfortunately the compiler can't in general assume that. > But I don't think GHC can do this because AFAIK, GHC will not reduce > literal string comparisions at compile time. Since Oct 1 it tries to. Unfortunately string literals seem to be floated out to toplevel before there are recognized as literals being arguments of (==), and the rule doesn't work. > [This is assuming that GHC's implementation of Typeof still uses > strings. This may not be true though since there was talk of adding > direct compiler support to make the implementation of typeof more > efficient and, more importantly, less prone to programmer error. It doesn't use strings for comparison but uniquely generated numbers. But it's not safe either: uniqueness of these numbers relies on TyCon objects being defined at the toplevel, with {-# NOINLINE #-}, and I'm not sure if common subexpression elimination doesn't mess this up (it corrupts similar cases). Anyway equality on statically known TypeRep is not done at compile time. I don't know why. -- __("< Marcin Kowalczyk * [EMAIL PROTECTED] http://qrczak.ids.net.pl/ \__/ ^^ QRCZAK ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
Re: Socket library ghc 5.02.1
From: "Sigbjorn Finne" <[EMAIL PROTECTED]> Cc: <[EMAIL PROTECTED]> Date: Tue, 27 Nov 2001 09:30:04 -0800 > > Conclusion: you're hosed with ghc-5.02.1 and its socket libs under > Win32. Sorry. > If you don't mind getting your hands a (little) bit dirty, here's a story that will work ghc-5.02.1: * edit SocketPrim.hi (and SocketPrim.p_hi), to instead of saying "Socket" in its __export section it says "Socket{MkSocket}" (you'll find the .hi file in imports/net/ inside your 5.02.1 tree). * compile up the attached NetExtra.hs as follows: foo$ ghc -c NetExtra.hs -fvia-C -fglasgow-exts -package net * import and include NetExtra with your socket code, e.g., Thanks Danke Mercie, this works (although I did not fully understand, what I was doing). Sven Eric ___ Glasgow-haskell-users mailing list [EMAIL PROTECTED] http://www.haskell.org/mailman/listinfo/glasgow-haskell-users