Giter Site home page Giter Site logo

printing infix types about ammonite HOT 5 CLOSED

com-lihaoyi avatar com-lihaoyi commented on June 15, 2024
printing infix types

from ammonite.

Comments (5)

lihaoyi avatar lihaoyi commented on June 15, 2024

This will actually be a whole bunch of work. Up till now we're just calling .toString on the type and printing whatever it gives us. There's quite a lot of space to improve if we do things manually (color, multi-line prettyprinting) but of course we'd actually need to write code to do it =/

from ammonite.

paulp avatar paulp commented on June 15, 2024

Yes, it's some work. The real home run would be pluggable type pretty-printing, just like the value printing and for the same reason. I want that type printed as Int -> String, not psp.std.Int -> psp.std.String, but there's no general way to know when and whether to dealias types or omit packages.

from ammonite.

lihaoyi avatar lihaoyi commented on June 15, 2024

Would something like "pick the shortest path from the things in scope to reach the desired type" work? That way if you import things like collection.mutable, then you'd get mutable.Buffer and such.

It could be expensive, but pretty-printing may not be that performance critical...

from ammonite.

paulp avatar paulp commented on June 15, 2024

There are a lot of heuristics one could apply, just like scala does, but it will never be satisfying if there's no way to control it. It's the same reason you have a PPrint trait for values: it matters how things print, but the same thing should print differently in different situations. You have to have more visibility into what's being printed than string concatenation offers if you want to do anything sensible under composition, a part of the type might need to be rendered in red because a configuration says so, they might need to be truncated or abbreviated to fit in a diagram, etc etc etc.

from ammonite.

lihaoyi avatar lihaoyi commented on June 15, 2024

This has been fixed in the latest merge. You can now define an implicit TPrint[T] in order to control how a type is pretty-printed. Naturally, it works recursively like values and will apply to any type being printed, even in a larger compount type, and it can make use of the TPrint[V] for any components of the type T by taking them as implicits.

from ammonite.

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.