Re: [Haskell-cafe] Suggestions for a hReadUntilStr implementation

2007-02-04 Thread Greg Fitzgerald

Matt,


should finish evaluating when either the timer has run out or

I recommend changing my implementation of hReadUntilStr so that the deadline
is calculated upfront (have a look at System.Time), and then reducing the
number of milliseconds for hReadUntilChar with each call to it.

Thanks,
Greg


On 2/4/07, Matt Revelle [EMAIL PROTECTED] wrote:


Thanks for the responses.

Greg, your implementation looks useful but it's a little different
than what I was thinking (my apologies, I wasn't very clear).

In the implementation you posted, the timeout parameter is used to
limit the amount of time spent waiting to read an individual character
- I was hoping to use the timeout as an initial value for a timer that
should start running when hReadUntilStr is evaluated and the function
should finish evaluating when either the timer has run out or when the
string match has been found.

Martin, thanks for the link.

Cheers,
Matt


On 2/3/07, Greg Fitzgerald [EMAIL PROTECTED] wrote:
 Hi Matt,

  hReadUntilStr - that is, a function that takes a Handle as an input
  source, a String to match, and a Num a  as the number of seconds to
  wait before returning a (String, Bool) where the String is all the
  text read from the Handle until either matching or timing out and the
  Bool is true if the input String was matched

 This might work for you: http://hpaste.org/289 .

 It throws an IO exception if hWaitForChar times out, and makes use of
lazy
 evaluation to schedule all the IO upfront so that grabbing the string
prefix
 can be done in pure code.

 Thanks,
 Greg

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Suggestions for a hReadUntilStr implementation

2007-02-03 Thread Martin DeMello

On 2/3/07, Matt Revelle [EMAIL PROTECTED] wrote:


hReadUntilStr :: (Num a) = Handle - String - a - IO (String, Bool)

Is this the wrong way to think about the problem?  If so, how should
it be handled?  If not, any ideas on the implementation?


Sounds like this would grow into a full-fledged expect-type program,
in which case http://www.informatik.uni-bremen.de/uniform/wb/ is
probably worth a look.

martin
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Suggestions for a hReadUntilStr implementation

2007-02-03 Thread Greg Fitzgerald

Hi Matt,


hReadUntilStr - that is, a function that takes a Handle as an input
source, a String to match, and a Num a  as the number of seconds to
wait before returning a (String, Bool) where the String is all the
text read from the Handle until either matching or timing out and the
Bool is true if the input String was matched


This might work for you: http://hpaste.org/289.

It throws an IO exception if hWaitForChar times out, and makes use of lazy
evaluation to schedule all the IO upfront so that grabbing the string prefix
can be done in pure code.

Thanks,
Greg
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Suggestions for a hReadUntilStr implementation

2007-02-03 Thread Matt Revelle

Thanks for the responses.

Greg, your implementation looks useful but it's a little different
than what I was thinking (my apologies, I wasn't very clear).

In the implementation you posted, the timeout parameter is used to
limit the amount of time spent waiting to read an individual character
- I was hoping to use the timeout as an initial value for a timer that
should start running when hReadUntilStr is evaluated and the function
should finish evaluating when either the timer has run out or when the
string match has been found.

Martin, thanks for the link.

Cheers,
Matt


On 2/3/07, Greg Fitzgerald [EMAIL PROTECTED] wrote:

Hi Matt,

 hReadUntilStr - that is, a function that takes a Handle as an input
 source, a String to match, and a Num a  as the number of seconds to
 wait before returning a (String, Bool) where the String is all the
 text read from the Handle until either matching or timing out and the
 Bool is true if the input String was matched

This might work for you: http://hpaste.org/289 .

It throws an IO exception if hWaitForChar times out, and makes use of lazy
evaluation to schedule all the IO upfront so that grabbing the string prefix
can be done in pure code.

Thanks,
Greg


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Suggestions for a hReadUntilStr implementation

2007-02-02 Thread Matt Revelle

Hey there,

A few weeks back I was thinking of writing a Haskell program that
automated a telnet session.  One function that could be useful is a
hReadUntilStr - that is, a function that takes a Handle as an input
source, a String to match, and a Num a  as the number of seconds to
wait before returning a (String, Bool) where the String is all the
text read from the Handle until either matching or timing out and the
Bool is true if the input String was matched.

Something like:

hReadUntilStr :: (Num a) = Handle - String - a - IO (String, Bool)

Is this the wrong way to think about the problem?  If so, how should
it be handled?  If not, any ideas on the implementation?

Any advice is appreciated.

Cheers,
Matt
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe