let is_rectangular d =
    if length d <= 1 then
      true
    else
      let allLengths = map length d in
      let firstLength = get allLengths 0 in
      let lengthEqualsFirstLength k = k = firstLength in
      for_all lengthEqualsFirstLength allLengths