flix / flix

The Flix Programming Language
https://flix.dev/
Other
2.19k stars 154 forks source link

`wget` outline #9393

Open jaschdoc opened 2 days ago

jaschdoc commented 2 days ago

I think there should be 4 parts of the aplication:

  1. The library that abstractly performs the get and write to file functionality. As a stretch goal I would like this to use the Range header where it downloads a limited sequence of bytes of the total file so we download a file in parallel. Additionally, if an error occurs (while downloading so we know the resource exists) we can retry the download until it succeeds (with some timeout). This is of course another stretch goal. Lastly, we could also consider supporting recursive downloads to some extent (a stretch goal again).
  2. A simple CLI library that performs argument parsing and also formats errors and help message(s) nicely. To begin with this can just print a minimal help message when the arguments are invalid. I'm thinking it is wget [args] url where one argument we could start with is the output filename.
  3. A test suite that has custom handlers for effects. As a bonues, this also demonstrates how effects can be used for dependency injection.
  4. The main function that parses args and calls the wget library and prints errors if any occurred.

I think the argument parser should be pure but we could experiment with reporting errors via an effect but that seems a little overkill for this project. Similarly, we could also add the failure to download part of a file as an effect and resume again. This would of course be handled by the library so it would not surface to main (which should at most use a helper function that eliminates the FileWrite and Http effects so we are left with IO + Net)

magnus-madsen commented 2 days ago

@mlutze Your comments?

magnus-madsen commented 2 days ago

Would it be possible to write a list of effects and functional signatures (including est. size) before starting to program?

magnus-madsen commented 2 days ago

I think parallelism is going too far. We also don't really know how it interacts with effects yet.

EDIT: it would be OK if no AE cross thread boundaries.

jaschdoc commented 2 days ago

I think parallelism is going too far. We also don't really know how it interacts with effects yet.

EDIT: it would be OK if no AE cross thread boundaries.

I think it is possible to keep AEs within threads

mlutze commented 1 day ago

I think it looks reasonable. Note that Flix already has an argument parsing library that you can use.

magnus-madsen commented 1 day ago

I think it looks reasonable. Note that Flix already has an argument parsing library that you can use.

But should he?

mlutze commented 1 day ago

I think it looks reasonable. Note that Flix already has an argument parsing library that you can use.

But should he?

Why not? It would be representative of a real program, right?

jaschdoc commented 1 day ago

I think it looks reasonable. Note that Flix already has an argument parsing library that you can use.

Which one?

magnus-madsen commented 1 day ago

GetOpt

jaschdoc commented 1 day ago

Maybe something like this?

mod Fget {

    type alias Options = { targetFile = String }

    pub def getResource(options: Options, url: { url = String }): String \ Http = ???

    pub def writeToDisk(options: Options): Unit \ FileWrite = ???

}
jaschdoc commented 1 day ago

Or maybe simpler interface:

mod Fget {

    type alias Options = { targetFile = String }

    pub def download(options: Options, url: String): String \ FileWrite + Http = ???

    def getResource(options: Options, url: { url = String }): String \ Http = ???

    def writeToDisk(options: Options): Unit \ FileWrite = ???

}