Giter Club home page Giter Club logo

Comments (14)

carlhammann avatar carlhammann commented on July 28, 2024 1

If that suits your needs, why not?

from cooked-validators.

carlhammann avatar carlhammann commented on July 28, 2024

There's pretty-printing for UtxoState, though, which we could use to implement Show. Probably Show was deepened unnecessary after we implemented pretty printing?

from cooked-validators.

gabrielhdt avatar gabrielhdt commented on July 28, 2024

So should we use the prettyCooked instance for Show as well?

from cooked-validators.

florentc avatar florentc commented on July 28, 2024

This is intended. In the end the plan is to remove requirements about Show instances for datum and redeemers (we already require PrettyCooked). So UtxoState will no longer be showable. Also, implementing Show from Pretty/PrettyCooked does not seem, if I am not mistaken, in the philosophy of what Show is usually expected to be: a raw printing of information. The pretty printing, on the other hand, takes liberties when it comes to printing, it omits info on purpose, etc. Besides, for your use case, in a repl, pretty-printing has upsides: for example it will adapt to your window size and line break when necessary while a conversion to string will blindly assume 80col-long lines.

I think this may be related to #234 in a way. Solving #234 would probably be the occasion to introduce some wrapper function or PrettyCooked instance to introduce convenient runAndPrettyPrint functions to use during experiments in the REPL

from cooked-validators.

gabrielhdt avatar gabrielhdt commented on July 28, 2024

if I am not mistaken, in the philosophy of what Show is usually expected to be: a raw printing of information

This is my opinion too, using pretty for Show seemed a bit strange to me. But how should I solve my problem? Is there a way to use the pretty function in the repl?

from cooked-validators.

florentc avatar florentc commented on July 28, 2024

You can use putDoc from Prettyprinter

from cooked-validators.

gabrielhdt avatar gabrielhdt commented on July 28, 2024

How can I convince the repl to use putDoc?

from cooked-validators.

florentc avatar florentc commented on July 28, 2024

By default Doc a, so DocCooked as well, are showable so you should see something if you just prettyCooked.
Alternatively, import Prettyprinter and putDoc . prettyCooked.

from cooked-validators.

gabrielhdt avatar gabrielhdt commented on July 28, 2024

I'm afraid I can't make things work out, could you tell me precisely how I should modify my snippet above to make it work?

from cooked-validators.

gabrielhdt avatar gabrielhdt commented on July 28, 2024

I see what you meant: but prettyCooked cannot work right away because the value returned is an Either ... ..., so this doesn't have any prettyCooked instance.

from cooked-validators.

florentc avatar florentc commented on July 28, 2024

There is prettyEndState in Pretty.Cooked. I could introduce a prettyRunResult :: Show a => PrettyCookedOpts -> (a, Either MockChainError UtxoState) -> DocCooked if you want. We already have pretty printing functions for state and mock chain error.

from cooked-validators.

gabrielhdt avatar gabrielhdt commented on July 28, 2024

Why not, but actually I'm more interested in knowing whether you think the behaviour I described in this bugreport is the expected one, or whether you think it's a bug.

from cooked-validators.

gabrielhdt avatar gabrielhdt commented on July 28, 2024

The "bug" being

cabal repl fails upon evaluation of some data of type Either ... UtxoState

from cooked-validators.

florentc avatar florentc commented on July 28, 2024

I think it is expected since UtxoState is no longer showable. The repl implicitly requires the returned value to be showable in order to print it. It does the same when evaluating any non Showable value.

It is now a matter of whether (and how) we want to restore an instance of Show for UtxoState.

In my opinion we should not for the reason I talked about above:

  • We have what we need to pretty print stuff better than what we would have using Show, we just lack wrapper functions in the user-facing API (see #234). @carlhammann and I plan to refresh the Testing module that has remained the same since V1. This would be the occasion to introduce functions dedicated to tinkering in the repl: they would run a mockchain and pretty print the result (IO ()) in addition to current functions that are expected to be used in test trees.
  • Basing Show on Pretty is not really what Show is about
  • Deriving Show would require datums to be Showable, which is currently the case but actually no longer relevant because they must implement PrettyCooked too.

from cooked-validators.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.