I was writing a function for boolean 2d arrays:
function foo(A::Array{Bool,2})
...
end
Evaluating and testing it with
A = randbool(3,3)
foo(A)
returns
ERROR: 'foo' has no method matching foo(::BitArray{2})
Obviously, randbool()
generates a BitArray
, whereas I assumed randbool()
would yield an Array{Bool}
.
How are Array{Bool}
and BitArray
related? Why do they both exist?
Can I write foo()
in such a way that it accept both input types using a single method (since I can't see a difference)?
randbool
isn't unreasonable — it's a pretty bad name! It's been deprecated in 0.4 and renamed tobitrand
(which sounds more like it'd create a BitArray). And there is a new methodrand(Bool, …)
to explicitly create an array ofBool
. You can start using these new definitions in 0.3 with the Compat package. – Penzance