Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implied types for intermediate declarations #200

Open
cjllanwarne opened this issue Mar 12, 2018 · 4 comments
Open

Implied types for intermediate declarations #200

cjllanwarne opened this issue Mar 12, 2018 · 4 comments

Comments

@cjllanwarne
Copy link
Contributor

I wonder whether this would be a great idea or a terrible one...

A lot of languages allow implied types (ie the language is strongly typed but the author doesn't need to type it out in full - they let the language do that for them).

Here's an example from a recent test case I was writing:

version draft-3

workflow lots_of_nesting {

  Boolean b0 = true
  Boolean b1 = true
  Boolean b2 = true

  Array[Int] i0s = range(2)
  Array[Int] i1s = range(2)
  Array[Int] i2s = range(2)

  String s0 = "hello"
  String s1 = "world"

  if (b0) {
    scatter(i0 in i0s) {
      if (b1) {
        scatter(i1 in i1s) {
          if (b2) {
            scatter(i2 in i2s) {
              String s = s0 + s1
            }
          }
        }
      }
    }
  }

  Array[Array[Array[String]?]?]? s_intermediate = s

  output {
    Array[Array[Array[String]?]?]? s_out = s_intermediate
  }
}

So that intermediate type... it's a bit messy to have to write it out in full (especially since it has to by typed out again in the outputs!).

Suggestion: Let users use value as a placeholder instead of the full type for intermediate values. We would still validate any future uses of the value as though it were fully typed, and I would still want full types for inputs and outputs (so that the interface can be read directly from the WDL file):

  value s_intermediate = s
  output {
    Array[Array[Array[String]?]?]? s_out = s_intermediate
  }
@cjllanwarne cjllanwarne changed the title Implied types for intermediate and output declarations Implied types for intermediate declarations Mar 12, 2018
@orodeh
Copy link
Contributor

orodeh commented Mar 12, 2018

@cjllanwarne, IMHO, we could consider it for version 2.0. The type landscape will significantly change after adding structs and directories (and hopefully removing objects).

I believe another name for this feature (at least in the ocaml world) is type-inference. It is complicated by generics and sub-typing, which we don't have as of yet, but may wish to add.

@geoffjentry
Copy link
Member

Here's hoping I never hear the phrase "Hindley-Milner" in relation to WDL :P

@orodeh
Copy link
Contributor

orodeh commented Mar 13, 2018

On a related note, dxWDL has to figure out variable and expression types, much like the value notation. There is a test case for this, which uses the WdlNamespace.lookupType. There are two issues:

  1. LookupType is private
  2. What is the equivalent in draft3?

Currently, I use a local copy of lookupType, but that is not really a good idea.

@jdidion
Copy link
Collaborator

jdidion commented Feb 7, 2024

I think the OP's example is extreme and it's not very common to encounter such long types. I don't think I'd want to introduce type inference just for this edge case. What about type aliases? For example:

type MyArray = Array[Array[Array[String]?]?]?

task foo {
  MyArray a = ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants