<html><body><div style="font-family: arial, helvetica, sans-serif; font-size: 12pt; color: #000000"><div>I have managed to convert in one direction like this:<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>```</div><div>sourceToShell :: forall a. SourceIO a -> Shell a<br>sourceToShell (S.SourceT act1) = Shell act2 where<br>    act2 :: FoldShell a r -> IO r<br>    act2 (FoldShell step begin done) = act1 (go begin) where<br>        go x = \case<br>            S.Stop -> done x<br>            S.Error e -> fail e<br>            S.Skip cont -> go x cont<br>            S.Yield val cont -> step x val >>= flip go cont<br>            S.Effect eff -> eff >>= go x</div><div>```<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><div>But in the other way (that is: shellToSource) I could not find any clean solution. I've got information from turtle's author that it's not possible directly by simple manupulation of data structures. It should however be possible by forking a new thread, write elements from Shell to some shared buffer and let StepT read from this buffer. But I have decided to re-implement some small set of turtle's functions (like 'ls') to produce SourceIO, instead of Shell, so this conversion is not needed any more.<br></div><div><br data-mce-bogus="1"></div><div>Zoran<br data-mce-bogus="1"></div><div><br data-mce-bogus="1"></div><hr id="zwchr" data-marker="__DIVIDER__"><div data-marker="__HEADERS__"><b>From: </b>"Bryan Richter" <bryan@haskell.foundation><br><b>To: </b>"Zoran Bošnjak" <zoran.bosnjak@via.si><br><b>Cc: </b>"haskell-cafe" <haskell-cafe@haskell.org><br><b>Sent: </b>Monday, July 10, 2023 9:19:44 AM<br><b>Subject: </b>Re: [Haskell-cafe] servant streaming question<br></div><div><br></div><div data-marker="__QUOTED_TEXT__"><div dir="ltr">In short, yes I think it should be possible. But messing with Shell / Fold always feels like doing a brain teaser rather than programming. If you figure it out, I would like to hear about it. :P<br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, 30 Jun 2023 at 21:00, Zoran Bošnjak <<a href="mailto:zoran.bosnjak@via.si" target="_blank" rel="nofollow noopener noreferrer">zoran.bosnjak@via.si</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb( 204 , 204 , 204 );padding-left:1ex">Hi all,<br>
I would like to reuse some streaming functions from the turtle package in the context of the servant streaming handler.<br>
<br>
Relevant references:<br>
<a href="https://hackage.haskell.org/package/turtle-1.6.1/docs/Turtle-Shell.html" rel="noreferrer nofollow noopener noreferrer" target="_blank">https://hackage.haskell.org/package/turtle-1.6.1/docs/Turtle-Shell.html</a><br>
<a href="https://hackage.haskell.org/package/turtle-1.6.1/docs/Turtle-Prelude.html" rel="noreferrer nofollow noopener noreferrer" target="_blank">https://hackage.haskell.org/package/turtle-1.6.1/docs/Turtle-Prelude.html</a><br>
<a href="https://hackage.haskell.org/package/servant-0.20/docs/Servant-Types-SourceT.html" rel="noreferrer nofollow noopener noreferrer" target="_blank">https://hackage.haskell.org/package/servant-0.20/docs/Servant-Types-SourceT.html</a><br>
<br>
As a simple example:<br>
<br>
<a href="http://Turtle.Prelude.ls" rel="noreferrer nofollow noopener noreferrer" target="_blank">Turtle.Prelude.ls</a> function represents stream of FilePaths (directory listing of some path)<br>
ls :: FilePath -> Shell FilePath<br>
<br>
Servant streaming is based around SourceT IO a, for example:<br>
type ListFiles = "ls" :> StreamGet NewlineFraming PlainText (SourceT IO FilePath)<br>
<br>
The problem is that the streaming (Shell a) is not exactly the same as servant's (SourceT IO a). But as far as I understand, they both represent "stream of values of type 'a'". My question is: Is a generic conversion function possible? Something like:<br>
<br>
shellToSource :: forall a. Shell a -> SourceIO a<br>
shellToSource = ??<br>
<br>
... such that I could reuse the 'ls' and write a streaming servant handler like this:<br>
<br>
listFilesHandler :: Handler (SourceIO FilePath)<br>
listFilesHandler = pure $ shellToSource $ <a href="http://Turtle.Prelude.ls" rel="noreferrer nofollow noopener noreferrer" target="_blank">Turtle.Prelude.ls</a> "somePath"<br>
<br>
Appreciate any suggestion.<br>
<br>
regards,<br>
Zoran<br>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer nofollow noopener noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div><br></div></div></body></html>