8000 Tabular mode · Issue #259 · hydromatic/morel · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Tabular mode #259
Closed
Closed
@julianhyde

Description

@julianhyde

The output in Morel's shell is currently identical to Standard ML's shell: lists (and, following #235, bags) are displayed in brackets, records are displayed in braces, and everything is munged onto a small number of lines. It would be nice if values that are a list (or bag) of records display similar to a relational database.

A new property "output" controls the behavior. Its default value is "classic", but a new value "tabular" would print tables.

- from e in scott.dept;
val it =
  [{deptno=10,dname="ACCOUNTING",loc="NEW YORK"},
   {deptno=20,dname="RESEARCH",loc="DALLAS"},
   {deptno=30,dname="SALES",loc="CHICAGO"},
   {deptno=40,dname="OPERATIONS",loc="BOSTON"}]
  : {deptno:int, dname:string, loc:string} bag
- Sys.set ("output", "tabular");
val it = () : unit
- from e in scott.dept;
deptno dname      loc
------ ---------- --------
    10 ACCOUNTING NEW YORK
    20 RESEARCH   DALLAS
    30 SALES      CHICAGO
    40 OPERATIONS BOSTON

val it : {deptno:int, dname:string, loc:string} bag

The above table is similar to the simple value of the tablefmt property of Python's tabulate library (albeit with less padding). Other values of tablefmt, such as github and rounded_grid, also make sense.

Initially "tabular" would only kick in if the value is a collection (list or bag) of records, and the fields of those records are atomic types (primitives and abstract types). Later, it could support top-level records, top-level atomic types, and collections of atomic types (e.g. int list), field values that are lists (e.g. {id: int, items: {id: int, name: string} list} list}) and field values that are sum types.

The val it : prefix (as opposed to the usual val it = ... : indicates that a pretty-printer has stepped in and has printed a value in the lines above. In future, there could be a chain of pretty-printers. There could be an API for custom pretty-printers, one part of which would be whether it can handle a value of a particular type.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0