Loading User Information from Channel 9
Something went wrong getting user information from Channel 9
Loading User Information from MSDN
Something went wrong getting user information from MSDN
Loading Visual Studio Achievements
Something went wrong getting the Visual Studio Achievements
E2E: Brian Beckman and Erik Meijer - Co/Contravariance in Physics and Programming, 3 of n
Jan 05, 2011 at 2:03 PM// Here is a simple select to get the fuel spent
// Now suppose the function we have the get the fuel spent needs XYZ
// then we can compose FuelSpentAt with ToXYZ
// Now if we separate the composition we see it is covariant (yes this was already covered)
// FuelSpentAt • ToXYZ • ToLatLon
IEnumerable<XYZ> orderedXYZs;//IEnumerable<LatLon> orderedLatLon;
// Now lets say we want to get the XYZs ordered by the rate that fuel was being consumed at that point. This is pretty straight forward with a function that takes XYZ and returns a rate.
orderedXYZs = times.Select(ToXYZ).OrderBy(FuelRateAt);
// Suppose though we only have a FuelRateAt function that takes LatLon in this case we can compose ToLatLon with FuelRateAt inside the OrderBy
// If we separate the composition we get the following. Now I beliebe OrderBy is contravariant since IComparable is contravariant, but I might be wrong. But the interesting thing is that this pattern is like the pattern Brian Beckman had in the physics example
orderedXYZs = times.Select(ToXYZ).Select(ToLatLon).OrderBy(FuelRateAt).Select(ToXYZ);
// ToXYZ • FuelRateAt • ToLatLon • ToXYZ
// Note the inverse (ToXYZ) is composed to the left of the FuelRateAt function