none
type list Clarification RRS feed

  • Question

  • Hello,

    In the language specification, type list is described as non-abstract because the empty list is directly of type list -- “The primitive types record and list are non-abstract because the empty record and the empty list are directly of those types” (section 5, second paragraph, last sentence).

    However, it seems like type list is the intrinsic (default) type of all lists, not just empty lists.

    Type.ListItem(type list) // returns any, which doesn’t make sense if this type were only for empty lists
    
    Value.ReplaceType({1,2,3}, type list) // succeeds, which doesn’t make sense if only an empty list is directly of type list

    Is there a special type for empty lists or by default are all lists of type list?

    Thank you,
    Ben

    (Related: Colin Banfield asked about this part of the specification a couple years ago; however, the answer given focused on type record.) 


    Friday, February 28, 2020 8:44 PM

Answers

  • On reflection, I think the spec is potentially a little misleading. The fundamental list type is a list of any. It is not abstract. Every other type of list is also a list of any. The fundamental record type is an open record with no defined fields. It is not abstract. Every other type of record is also a record of this type.

    “type record” and “type [...]” are the same thing.

    “type list” and “type {any}” are the same thing.

    M> Type.Is(type record, type [])
    false

    M> Type.Is(type record, type [...])
    true

    M> Type.Is(type [A=any, optional B=any, ...], type [...])
    true

    M> Type.Is(type list, type {any})
    false

    M> Type.Is(type {nullable number}, type {any})
    true

    Monday, March 16, 2020 8:44 PM
  • Hi Ben. Yes, that expression returns true in the product today.

    Ehren

    • Marked as answer by Ben Gribaudo Friday, April 10, 2020 8:23 PM
    Thursday, April 2, 2020 8:59 PM
    Owner

All replies

  • On reflection, I think the spec is potentially a little misleading. The fundamental list type is a list of any. It is not abstract. Every other type of list is also a list of any. The fundamental record type is an open record with no defined fields. It is not abstract. Every other type of record is also a record of this type.

    “type record” and “type [...]” are the same thing.

    “type list” and “type {any}” are the same thing.

    M> Type.Is(type record, type [])
    false

    M> Type.Is(type record, type [...])
    true

    M> Type.Is(type [A=any, optional B=any, ...], type [...])
    true

    M> Type.Is(type list, type {any})
    false

    M> Type.Is(type {nullable number}, type {any})
    true

    Monday, March 16, 2020 8:44 PM
  • Thank you, Curt.

    M> Type.Is(type list, type {any})

    false

    Shouldn't this be true?
    Wednesday, March 18, 2020 3:06 PM
  • Hi Ben. Yes, that expression returns true in the product today.

    Ehren

    • Marked as answer by Ben Gribaudo Friday, April 10, 2020 8:23 PM
    Thursday, April 2, 2020 8:59 PM
    Owner
  • Thanks, Ehren!
    Friday, April 10, 2020 8:23 PM