The problem of animals and foods

added by bnaya
2/8/2013 10:53:55 AM

0 Kicks, 55 Views

this is a short post that is dealing with a classic riddle. I was thinking on this riddle when I was trying to figure out a Scala feature. we are having (at Sela Group) a small Scala study group led by Israel Tabadi and while we were going over Scala's abstract type (which is by the way a cool implementation) I was thinking about the .NET equivalent solution. I will use the problem of "animals and foods" (taken from here) as an anchor's point. The problem: assuming an Animal with a method, Eat, which eats some food. and the riddle is, how can you restrict a Cow (which derived from an Animal), to eat nothing but Grass (at compile time). A Cow can't eat an arbitrary food like Fish. the idea is to restrict a Cow to a specialize