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

Type system #36

Closed
majastrz opened this issue Jun 16, 2020 · 2 comments · Fixed by #914
Closed

Type system #36

majastrz opened this issue Jun 16, 2020 · 2 comments · Fixed by #914
Assignees
Labels
documentation Improvements or additions to documentation syntax Related to language syntax
Milestone

Comments

@majastrz
Copy link
Member

majastrz commented Jun 16, 2020

Types

We will support the following types:

  • Built-In Types
    • error
    • any
    • string
    • object
    • array
    • bool
    • int
    • number
    • resource
  • named non-resource types (such as azrm://ResourceGroup, azrm://Deployment, azrm://Parameter, etc.)
  • named resource types (such as azrm://Microsoft.Network/virtualNetworks@2019-06-01)
  • union types (needed to represent functions accepting multiple parameter types)
  • discriminated union types (needed to represent polymorphic resource types)

Union types

One example why we need union types is the concat() function (and any other function with multi-type arguments).

One possible way to model the concat function using pseudo-TypeScript:

concat(x: string | int, y: string | int, ...): string
concat(x: array, y: array, ...): array

Resource Managers

In past discussions, we kept calling azrm a "provider", but is too similar to an ARM Resource Provider. I propose we call this a "Resource Manager" instead. (RM for short.)

Considerations

  1. Built-in types (string, number, int, bool, array, object) are not specific to an RM.
  2. Named resource and non-resource types are RM-specific.
  3. Functions need to be split into RM-specific and non RM-specific groups.

Implicit conversion

Here are the rules that determine how values can be assigned.

  • all values are assignable to declarations of the same type
  • all types are assignable to any
  • int is assignable to number
  • int is assignable to int | string
  • string is assignable to int | string
  • resource is assignable to object
  • azrm://ResourceGroup is assignable to object but not to resource
  • azrm://Microsoft.Network/virtualNetworks@2019-06-01 is assignable to resource
  • azrm://Microsoft.Network/virtualNetworks@2019-05-01 is NOT assignable to azrm://Microsoft.Network/virtualNetworks@2019-06-01 or vice versa

Explicit conversion

Explicit type conversions should be performed via function invocations if such a function is available.

@shenglol
Copy link
Contributor

shenglol commented Jun 18, 2020

Proposal for string literal union and refinement type syntax

In an ARM template we can specify allowed values (mostly for string, not sure if it works for object), and in our new DSL the syntax looks like this (correct me if I'm wrong):

parameter myParameter string {
  allowedValues: [
    "foo"
    "bar"
  ]
} = ...

When checking the type of myResource the type system will need to check 1. if it is a string; 2. if its value is within allowedValues. This means the type of myResource is essentially a string literal union, so I wonder if it makes sense for us to support the following syntax like TypeScript does:

parameter myParameter "foo" | "bar" = ...

Similarly, you can specify minValue and maxValue for int parameters, and minLength and maxLength for string parameters. Here's how currently an int parameter with constraints looks like in our new DSL:

parameter myParameter int {
  minValue: 0,
  maxValue: 10000
} = ...

This appears to be a Refinement Type. PLs like LiquidHaskell and Scala support it. We might not want a complete Refinement Type system because our new DSL is not a general purpose PL, but we will need implement it for parameter checking. I'm thinking about something like the following for int parameters:

parameter myParameter { int | x >= 0 && x <= 10000 } = ...

For string parameters:

parameter myParameter { string | x.length > 0 && x.length <= 64 } = ...

@majastrz
Copy link
Member Author

This is cool. We should talk about these at one meetings once we're done with loops/conditions.

One comment about the type system. The compiler won't be the one checking that the value is in the allowed values list. It will still be ARM.

@majastrz majastrz added the syntax Related to language syntax label Jun 19, 2020
@alex-frankel alex-frankel added this to the v0.1 milestone Aug 11, 2020
@majastrz majastrz self-assigned this Aug 22, 2020
@alex-frankel alex-frankel modified the milestones: v0.1, v0.2 Sep 8, 2020
@alex-frankel alex-frankel added the documentation Improvements or additions to documentation label Sep 28, 2020
@ghost ghost locked as resolved and limited conversation to collaborators May 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Improvements or additions to documentation syntax Related to language syntax
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants