Skip to content

Ranges can be UDTs with syntactic sugar for constructing them #310

@swernli

Description

@swernli

Yes, I think ranges really are just UDTs with syntactic sugar for constructing them. In old Q#, you could already manually "update" any range field:

function UpdateRangeStart(r : Range, start: Int) : Range {
    return start..RangeStep(r)..RangeEnd(r);
}

function UpdateRangeStep(r : Range, step : Int) : Range {
    return RangeStart(r)..step..RangeEnd(r);
}

function UpdateRangeEnd(r : Range, end : Int) : Range {
    return RangeStart(r)..RangeStep(r)..end;
}

So I don't see any problem with w/ being sugar for those functions. In fact I'd actually recommend we refactor the compiler to literally define Range in the core library:

newtype Range = (Start : Int, Step : Int, End : Int);

and lower range expressions into constructor calls referencing the core type. That would remove all the special casing for "primitive" fields.

Originally posted by @SamarSha in #308 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions