Gabriella439 / turtle

Shell programming, Haskell style
BSD 3-Clause "New" or "Revised" License
943 stars 90 forks source link

Add Turtle.Format.makePrinter function #416

Closed unclechu closed 2 years ago

unclechu commented 2 years ago

I was trying to implement some abstraction on top of Turtle to redirect the default output (stdout and/or stderr) to a logger function withing some monad where the logger is available. While I was able to implement most of the Turtle function in one way or another it turned out it’s not that trivial to implement custom printf and eprintf since (>>-) of Turtle.Format.Format is not exposed.

This change adds makePrinter function that just adds extra argument for printf that is a printer function ending with m () as Format result. The implementation is trivial (flip (>>-)), printf and eprintf are reimplemented using this function.

unclechu commented 2 years ago

@Gabriel439 I have some doubts about the name of the function. Maybe it’s better to explicitly say that it’s about Format? Like name the function not just makePrinter but makeFormatPrinter. What do you think?

Gabriella439 commented 2 years ago

@unclechu: Another option would be to just expose the Format constructor so that people can use (>>-) directly. There's no real reason that it needs to be hidden

unclechu commented 2 years ago

@Gabriel439 Yeah, I would like to just get it exposed in the first place so I wouldn’t have this kind of issue.

Gabriella439 commented 2 years ago

I put up a PR to expose the Format constructor here: https://github.com/Gabriel439/turtle/pull/417

unclechu commented 2 years ago

@Gabriel439 I did the same meanwhile https://github.com/Gabriel439/turtle/pull/418 :sweat_smile: Close either one. Anyway, closing this one.