Home liberachat/#haskell: Logs Calendar

Logs: liberachat/#haskell

←Prev  Next→ 1,803,948 events total
2021-08-02 02:14:27 <euouae> Hmm, alright. I'll heed your advice
2021-08-02 02:15:48 <sm> at least skim their user manuals, and understand the concepts of package dbs and the various places haskell libraries and executables can be
2021-08-02 02:16:40 <sm> also, I like this beginner book:
2021-08-02 02:16:40 <sm> @where HTAC
2021-08-02 02:16:40 <lambdabot> "Haskell Tutorial and Cookbook" by Mark Watson in 2017-09-04 at <https://leanpub.com/haskell-cookbook>
2021-08-02 02:18:04 arahael1 joins (~arahael@124-150-74-227.tpgi.com.au)
2021-08-02 02:18:19 <euouae> That's a cool publisher
2021-08-02 02:18:46 × Arahael quits (~arahael@14-200-228-14.tpgi.com.au) (Ping timeout: 272 seconds)
2021-08-02 02:19:50 × pschorf quits (~user@c-73-77-28-188.hsd1.tx.comcast.net) (Remote host closed the connection)
2021-08-02 02:20:35 finn_elija joins (~finn_elij@user/finn-elija/x-0085643)
2021-08-02 02:20:35 FinnElija is now known as Guest7086
2021-08-02 02:20:35 × Guest7086 quits (~finn_elij@user/finn-elija/x-0085643) (Killed (sodium.libera.chat (Nickname regained by services)))
2021-08-02 02:20:35 finn_elija is now known as FinnElija
2021-08-02 02:21:01 × merijn quits (~merijn@83-160-49-249.ip.xs4all.nl) (Ping timeout: 265 seconds)
2021-08-02 02:28:20 × td_ quits (~td@94.134.91.166) (Ping timeout: 272 seconds)
2021-08-02 02:29:33 td_ joins (~td@muedsl-82-207-238-030.citykom.de)
2021-08-02 02:31:02 lavaman joins (~lavaman@98.38.249.169)
2021-08-02 02:31:06 phma joins (phma@2001:0:c38c:c38c:cc7:e519:bcd3:2ebd)
2021-08-02 02:34:09 falafel joins (~falafel@pool-96-255-70-50.washdc.fios.verizon.net)
2021-08-02 02:35:56 × lavaman quits (~lavaman@98.38.249.169) (Ping timeout: 272 seconds)
2021-08-02 02:38:43 phma_ joins (phma@2001:5b0:211b:e2d8:c072:cd43:475:d917)
2021-08-02 02:39:06 × jao quits (~jao@cpc103048-sgyl39-2-0-cust502.18-2.cable.virginm.net) (Ping timeout: 272 seconds)
2021-08-02 02:39:08 × phma quits (phma@2001:0:c38c:c38c:cc7:e519:bcd3:2ebd) (Ping timeout: 256 seconds)
2021-08-02 02:45:42 jao joins (~jao@cpc103048-sgyl39-2-0-cust502.18-2.cable.virginm.net)
2021-08-02 02:53:31 guest86 joins (~guest86@2001:8004:1420:14ac:b1cc:c092:84b0:86f6)
2021-08-02 02:54:18 × curiousgay quits (~curiousga@77-120-186-48.kha.volia.net) (Ping timeout: 272 seconds)
2021-08-02 02:54:53 <guest86> Hello, I am getting back into Haskell after being away from it for a few years. I am trying to interact with a process using System.Process.Typed. The process at some point will print: "INPUT?: " to stdout and I want to be able to enter something via STDIN when that happens.
2021-08-02 02:55:28 <guest86> https://paste.tomsmeding.com/iFHG9bjw <- I am trying to figure out how to read from stdin until this happens. Is there an easier way. Also, what do I need to do to whileM to have it work in IO?
2021-08-02 02:56:21 hmmmas joins (~fidnc@183.217.200.220)
2021-08-02 02:59:16 <monochrom> Uh, you begin with "x <- hGetLine (getStdout p)", and henceforth you never even take a look at what's in x?
2021-08-02 02:59:44 <monochrom> I guess this is why everyone else was saying "the unsued-var warning is very informative".
2021-08-02 02:59:56 <guest86> monochrom in this case I know I can ignore the first line, its a toy example
2021-08-02 03:01:06 × wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Ping timeout: 240 seconds)
2021-08-02 03:01:49 <guest86> The process I am talking toL
2021-08-02 03:01:51 <guest86> #!/usr/bin/env python3
2021-08-02 03:01:52 <guest86> print("Hello there")
2021-08-02 03:01:52 <guest86> print("INPUT?:", end=' ')
2021-08-02 03:01:53 <guest86> val = input()
2021-08-02 03:01:53 <guest86> print(f"You entered:{val}")
2021-08-02 03:02:12 <monochrom> OK so what's not working?
2021-08-02 03:02:58 <monochrom> (That is a guiding question.)
2021-08-02 03:03:09 jess joins (~jess@libera/staff/jess)
2021-08-02 03:04:18 <monochrom> (And training people to take the effort to describe observations.)
2021-08-02 03:07:30 <guest86> Well, the first issue is that
2021-08-02 03:07:31 <guest86> whileM (not (hIsEOF (getStdout p))) $ do
2021-08-02 03:08:13 <guest86> because hIsEOF (getStdout p) is IO Bool, and whileM wants a Bool
2021-08-02 03:09:20 wroathe joins (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net)
2021-08-02 03:09:30 × MQ-17J quits (~MQ-17J@8.6.144.192) (Ping timeout: 272 seconds)
2021-08-02 03:09:48 <monochrom> Uh which package does Control.Monad.Loop come from?
2021-08-02 03:10:09 <guest86> https://hackage.haskell.org/package/monad-loops-0.4.3/docs/Control-Monad-Loops.html
2021-08-02 03:10:28 <monochrom> Then whileM totally wants IO Bool alright.
2021-08-02 03:10:35 <dsal> `untilJust` is a pretty cool name.
2021-08-02 03:10:40 <monochrom> It is "not" that doesn't like IO Bool.
2021-08-02 03:11:21 <guest86> oh, wow, yeah looking at the compiler output you're totally right
2021-08-02 03:11:58 <monochrom> You can use "fmap" to bridge the gap.
2021-08-02 03:12:49 MQ-17J joins (~MQ-17J@d14-69-206-129.try.wideopenwest.com)
2021-08-02 03:13:56 × Gurkenglas quits (~Gurkengla@dslb-002-203-144-156.002.203.pools.vodafone-ip.de) (Ping timeout: 272 seconds)
2021-08-02 03:14:12 <monochrom> You will run into the second problem after you fix that.
2021-08-02 03:14:20 <guest86> thanks
2021-08-02 03:14:34 × wroathe quits (~wroathe@c-68-54-25-135.hsd1.mn.comcast.net) (Ping timeout: 272 seconds)
2021-08-02 03:15:38 × ham quits (~ham4@user/ham) (Ping timeout: 265 seconds)
2021-08-02 03:15:59 dsal watches monochrom play Haskell chess
2021-08-02 03:16:05 ham2 joins (~ham4@d8D8627D5.access.telenet.be)
2021-08-02 03:16:10 <dsal> type checks in three moves
2021-08-02 03:16:24 <monochrom> haha
2021-08-02 03:16:43 <monochrom> Well the second problem is mistaking EOF with "no data for now".
2021-08-02 03:17:11 <monochrom> If the child process doesn't close its stdout, your side will not see EOF.
2021-08-02 03:17:32 <guest86> So I suppose I can just get the characters until I see "INPUT?: "
2021-08-02 03:17:48 <monochrom> And most processes, including this one, doesn't close stdout until termination.
2021-08-02 03:17:58 <monochrom> Yes.
2021-08-02 03:18:05 <guest86> I guess the issue I was having was that I was using hGetLine, but in this case there isn't a whole line to be gotten
2021-08-02 03:18:45 <guest86> is hWaitForInput the way to go?
2021-08-02 03:19:17 curiousgay joins (~curiousga@77-120-186-48.kha.volia.net)
2021-08-02 03:19:50 <monochrom> You will realize that you're making an XY problem when you find out that hGetChar already does the waiting.
2021-08-02 03:20:31 <monochrom> There is a third problem after you fix that.
2021-08-02 03:21:42 <monochrom> The third problem can only be fixed in the Python script. Or generally child code. Parent code has absolutely no say over this. None. Zilch.
2021-08-02 03:23:34 <pavonia> What is the third problem?
2021-08-02 03:24:09 <monochrom> "I see my stdout is a pipe, not a terminal, so let me switch to block buffering. My buffer is a gazillion bytes."
2021-08-02 03:24:43 <monochrom> This buffering is highly local and private. Even the kernel doesn't know.
2021-08-02 03:25:01 <guest86> Ah okay, so I think my approach is wrong.
2021-08-02 03:25:34 <monochrom> The only solution is rewrite child code to switch back to line buffering. Or add explicit "flush" calls.
2021-08-02 03:25:36 <guest86> What I would like to do is be able to monitor a python script (that I cannot necessarily modify) and send input to it under certain conditions
2021-08-02 03:26:12 <guest86> Am I taking the right approach?
2021-08-02 03:26:33 <guest86> I mean, in general, is there a better approach I should be using?
2021-08-02 03:26:53 <monochrom> Err actually I just recall a non-intrusive solution. You now have to make some syscalls to allocate a pseudo terminal. Then the child sees a terminal and will behave.
2021-08-02 03:27:49 <monochrom> But even I haven't learned the relevant syscalls. This gets highly technical and unix-specific.
2021-08-02 03:28:36 × zebrag quits (~chris@user/zebrag) (Quit: Konversation terminated!)
2021-08-02 03:29:09 <monochrom> dsal had the correct count. :)
2021-08-02 03:29:17 <euouae> can't you just pipe the script to a file and read from the file, ignoring eof?
2021-08-02 03:29:34 <monochrom> Same buffering delay.
2021-08-02 03:29:52 <monochrom> You will find the file empty for a long, long time.
2021-08-02 03:29:54 <guest86> The script has a line of input (a confirmation code) that I won't have until runtime
2021-08-02 03:30:38 <euouae> Right... man tty and go from there
2021-08-02 03:30:57 <euouae> pty*
2021-08-02 03:31:00 <monochrom> Except now you have to make unix syscalls but you're in Haskell
2021-08-02 03:31:32 <euouae> No-one said all of it needs to be done in Haskell :P either write that component in C or use FFI
2021-08-02 03:31:54 <guest86> Yeah good point. I will explore some options. Maybe in this case I can in fact modify the python script
2021-08-02 03:32:20 <guest86> Actually, I don't think I can. So, I guess I will have to look into pty
2021-08-02 03:32:58 <monochrom> Oh the standard library has System.Posix.Terminal.openPseudoTerminal. I guess it's already half the way.
2021-08-02 03:33:04 <euouae> monochrom: You can just use script -c

All times are in UTC.