seq{
for bit in BitArray(10) do
yield bit
}
bit
is of bool
type. I checked with ILSpy and there's an explicit cast added in one of closures generated.
BitArray
implements only plain (not generic) IEnumerable
. How does F# know that it's a bool
?
The slope of a linear function is calculated by rearranging the equation to its general form, f(x) = mx + c; where m is the slope. The vertex of a quadratic function is calculated by rearranging the equation to its general form, f(x) = a(x – h)2 + k; where (h, k) is the vertex.
more ... A special relationship where each input has a single output. It is often written as "f(x)" where x is the input value. Example: f(x) = x/2 ("f of x equals x divided by 2")
What Does f ' Say About f ? The first derivative of a function is an expression which tells us the slope of a tangent line to the curve at any instant. Because of this definition, the first derivative of a function tells us much about the function.
According to the F# 4.1 specification's Section 6.5.6 Sequence Iteration Expressions, F# does casting even for a non-generic IEnumerable
if the IEnumerable
has an Item
property with a non-object
type (highlighting mine):
An expression of the following form is a sequence iteration expression:
for pat in expr1 do expr2 done
The type of pat is the same as the return type of the Current property on the enumerator value. However, if the Current property has return type obj and the collection type ty has an Item property with a more specific (non-object) return type ty2, type ty2 is used instead, and a dynamic cast is inserted to convert v.Current to ty2.
If we look at the source code for BitArray
, we see that it does indeed have an Item
property with type bool
:
public bool this[int index] {
get {
return Get(index);
}
set {
Set(index,value);
}
}
Thus, F# will explicitly cast to bool
while iterating.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With