This repository was archived by the owner on Jan 12, 2024. It is now read-only.

Description
Describe the bug
Default uses deprecated new array syntax to create default and often invalid values for generic types. Because Mapped uses Default to pre-allocate the array being mapped into, it can inadvertently trigger asserts in runtimes that check for valid content on creation of values. We should find a way to refactor Mapped to protect against this.
One possible suggestion for a new implementation (courtesy of @cgranade):
// pseudocode
function Mapped<'T, 'O>(fn : 'T -> 'O, arr : 'T[]) : 'O {
if Length(arr) == 0 {
return [];
}
let first = fn(arr[0]);
mutable retval = [first; size=Length(arr)];
for idx in 1..Length(arr) - 1{
set retval w/ idx <- fn(arr[idx]);
}
return retval;
}
Related:
microsoft/qsharp-runtime#977
microsoft/qsharp-runtime#975