unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.73k stars 266 forks source link

ucm command: view only type signature #2801

Open ceedubs opened 2 years ago

ceedubs commented 2 years ago

I find that I'm often just interested in the type signature of a term, but when I view myTerm the implementation is long enough that I have to page back to see the type signature. It'd be nice to have an easy way to view just the type signature.

For example instead of:

.> view .base.List.map

  base.List.map : (a ->{𝕖} b) -> [a] ->{𝕖} [b]
  base.List.map f a =
    go i as acc =
      match List.at i as with
        None   -> acc
        Some a ->
          use Nat +
          go (i + 1) as (acc :+ f a)
    go 0 a []

I'd want something like:

.> signature .base.List.map

  base.List.map : (a ->{𝕖} b) -> [a] ->{𝕖} [b]

Some possible command names that come to mind:

NOTE: if the fzf completion options showed the type signature when doing the no-arg version of view that would probably be good enough for me and I don't know that I'd feel the need for a separate command.

emilhotkowski commented 2 years ago
  1. Do you want to add this to UCM?
  2. Which option do we prefer? (adding new command is easy IMO by adding parameter to HandleShowDefinition function onlyType or something similar )

If this is for grab then I can do it.

ceedubs commented 2 years ago

@emilhotkowski Thanks that would be great! My inclination would be to add a view.signature command to ucm. But I can't speak for others.

emilhotkowski commented 2 years ago

I'll add code that can handle this option, but if we choose differently it should be easy to fix PR.

hojberg commented 2 years ago

a view.summary version might be a separate option here that allows you to view summaries of types as well as terms.

so like unique type Nonempty a might be the summary of unique type Nonempty a = Nonempty a [a] or something like that.

We use something similar to this in the UI for showing results in the Finder (and eventually for hovers).

emilhotkowski commented 2 years ago

If we need something more complicated then what I thought than I'd need some guidance to implement this 🤪