Proposal: Add sequenceWhile and SequenceWhile_ to Control.Monad
ganesh.sittampalam at credit-suisse.com
Sat May 9 15:47:30 EDT 2009
(I've reordered the quoting a bit to make things fit together better in
Dominic Steinitz wrote:
> Sittampalam, Ganesh wrote:
>> It's also a bit specialised for my taste. A better option would be to
>> have a takeWhileM which would allow sequenceWhile_ and sequenceWhile
>> to be built from that and sequence_/sequence.
> I'd argue that some of the functions in Control.Monad are more
I guess that's true, though I don't think that's in itself an argument
for adding more.
> I'm not sure what you had in mind for takeWhileM. Can you give a type
> signature / behaviour description?
Oops, it's not implementable. Sorry!
(What I had in mind was something like takeWhileM :: Monad m => (a ->
Bool) -> [m a] -> [m a], but it would have to actually run the monadic
actions to figure out the structure of the list)
>> This last line should probably be return  for consistency with
>> takeWhile etc. The downside of that is that the monadic effect
>> associating with producing y has been run but then the value is
>> thrown away.
> I use sequenceWhile to go through actions and stop at the one that
> "fails" (in some sense). I like to know what caused the failure so I
> return [y]. It did occur to me that one could argue that it should
> return . But then you know something "failed" but not how.
> I'd be happy with the composition of two library functions *provided*
> I can get hold of the value of the last run action.
I think the While name needs to change, in that case. I can't think of a
nice sounding alternative though :-(
Please access the attached hyperlink for an important electronic communications disclaimer:
More information about the Libraries