diff --git a/src/Simulation/QsharpCore/Arrays/Empty.cs b/src/Simulation/QsharpCore/Arrays/Empty.cs new file mode 100644 index 00000000000..7cb7448a393 --- /dev/null +++ b/src/Simulation/QsharpCore/Arrays/Empty.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using System; +using Microsoft.Quantum.Simulation.Core; + +namespace Microsoft.Quantum.Arrays +{ + public partial class EmptyArray<__TElement__> + { + public class Native : EmptyArray<__TElement__> + { + public Native(IOperationFactory m) : base(m) { } + public override Func> __Body__ => _ => + new QArray<__TElement__>(); + } + } + +} diff --git a/src/Simulation/QsharpCore/Arrays/Empty.qs b/src/Simulation/QsharpCore/Arrays/Empty.qs new file mode 100644 index 00000000000..0d586def7a2 --- /dev/null +++ b/src/Simulation/QsharpCore/Arrays/Empty.qs @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Arrays { + + /// # Summary + /// Returns the empty array of a given type. + /// + /// # Type Parameters + /// ## 'TElement + /// The type of elements of the array. + /// + /// # Output + /// The empty array. + /// + /// # Example + /// ```Q# + /// let empty = EmptyArray(); + /// ``` + function EmptyArray<'TElement>() : 'TElement[] { + body intrinsic; + } + +} diff --git a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Arrays/Tests.qs b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Arrays/Tests.qs new file mode 100644 index 00000000000..3bbc428984a --- /dev/null +++ b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Arrays/Tests.qs @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +namespace Microsoft.Quantum.Arrays { + open Microsoft.Quantum.Diagnostics; + + /// # Summary + /// Checks that empty arrays are indeed empty. + @Test("QuantumSimulator") + @Test("ToffoliSimulator") + function EmptyArraysAreEmpty() : Unit { + Fact( + Length(EmptyArray()) == 0, + "Empty array of type Int[] was not actually empty." + ); + Fact( + Length(EmptyArray<(Double, Pauli[])>()) == 0, + "Empty array of type (Double, Pauli[])[] was not actually empty." + ); + } + +} diff --git a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Random/Tests.qs b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Random/Tests.qs index ab8416de9e6..aff82adbc8a 100644 --- a/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Random/Tests.qs +++ b/src/Simulation/Simulators.Tests/TestProjects/IntrinsicTests/Random/Tests.qs @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + namespace Microsoft.Quantum.Tests { open Microsoft.Quantum.Intrinsic; open Microsoft.Quantum.Canon;