[Haskell-cafe] servant streaming question

Bryan Richter bryan at haskell.foundation
Mon Jul 10 07:19:44 UTC 2023


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

On Fri, 30 Jun 2023 at 21:00, Zoran BoĆĄnjak <zoran.bosnjak at via.si> wrote:

> Hi all,
> I would like to reuse some streaming functions from the turtle package in
> the context of the servant streaming handler.
>
> Relevant references:
> https://hackage.haskell.org/package/turtle-1.6.1/docs/Turtle-Shell.html
> https://hackage.haskell.org/package/turtle-1.6.1/docs/Turtle-Prelude.html
>
> https://hackage.haskell.org/package/servant-0.20/docs/Servant-Types-SourceT.html
>
> As a simple example:
>
> Turtle.Prelude.ls function represents stream of FilePaths (directory
> listing of some path)
> ls :: FilePath -> Shell FilePath
>
> Servant streaming is based around SourceT IO a, for example:
> type ListFiles = "ls" :> StreamGet NewlineFraming PlainText (SourceT IO
> FilePath)
>
> 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:
>
> shellToSource :: forall a. Shell a -> SourceIO a
> shellToSource = ??
>
> ... such that I could reuse the 'ls' and write a streaming servant handler
> like this:
>
> listFilesHandler :: Handler (SourceIO FilePath)
> listFilesHandler = pure $ shellToSource $ Turtle.Prelude.ls "somePath"
>
> Appreciate any suggestion.
>
> regards,
> Zoran
> _______________________________________________
> Haskell-Cafe mailing list
> To (un)subscribe, modify options or view archives go to:
> http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
> Only members subscribed via the mailman list are allowed to post.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20230710/7d26c7b1/attachment.html>


More information about the Haskell-Cafe mailing list