Array2 bug murder :)

Anoq of the Sun anoq@HardcoreProcessing.com
Sun, 25 Feb 2001 11:26:59 +0100


Hello!


I seem to have found a bug in Array2 in MLton.
This code wouldn't typecheck (I got a Unify Con error):


fun test (arr : int Array2.array) =
      case Int.fromString "1" of
        NONE => Array2.row (arr, 0)
      | SOME(i) => Array2.column(arr, 0)


Doing like this worked fine though:


fun test (arr : int Array2.array) =
      case Int.fromString "1" of
        NONE => Array2.row (arr, 0)
      (* | SOME(i) => Array2.column(arr, 0) *)


The problem was in Array2.column - it returned
an array when it should have returned a vector.
Here's a new version of the column function
(in basis-libarary/arrays-and-vectors/array2.sml)
which works correctly (and the buggy part as comment):

fun column(a as Array{rows, cols, ...}, c) =
	 if safe andalso geu(c, cols)
	    then raise Subscript
	 else
           Vector.tabulate(rows, fn r => sub(a, r, c))
(*
	    let val a' = Primitive.Array.array rows
	    in Util.naturalForeach(rows, fn r =>
				   Array.update(a', r, sub(a, r, c)));
	       a'
	    end
*)

Is this a known bug or a new one? :)

I'm still using my modified version
of 1999-7-12 (on native Linux).


Cheers
-- 
http://www.HardcoreProcessing.com