I’ve heard that Scala has path-dependent types. It’s something to do with inner-classes but what does this actually mean and why do I care?
I’ve heard that Scala has path-dependent types. It’s something to do with inner-classes but
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
My favorite example:
So, the type of
Coordinateis dependent on the instance ofBoardfrom which it was instantiated. There are all sort of things that can be accomplished with this, giving a sort of type safety that is dependent on values and not types alone.This might sound like dependent types, but it is more limited. For example, the type of
occupiedis dependent on the value ofBoard. Above, the last line doesn’t work because the type ofc2isb2.Coordinate, whileoccupied‘s type isSet[b1.Coordinate]. Note that one can use another identifier with the same type ofb1, so it is not the identifierb1that is associated with the type. For example, the following works: