5 ms·
Looking at the new features. Can anyone say what dependent function types are good for? In the example (https://dotty.epfl.ch/docs/reference/new-types/dependent
by rnikander 5y ago
Looking at the new features. Can anyone say what dependent function types are good for? In the example (https://dotty.epfl.ch/docs/reference/new-types/dependent-function-types.html https://dotty.epfl.ch/docs/reference/new-types/dependent-fun...), what's the difference between:
def extractKey(e: Entry): e.Key = e.key
and:
def extractKey(e: Entry): Entry.Key = e.key // the way I'd normally think of it
- esarbe 5y agoWith dependent types, each `e.key` has it's own and separate type. So, if you have two `e`s, the type of the first e's key will not match the type of the second e's key. So, with: def process(p: Path, key: p.Key): Something = ??? this will not compile: val p1: Path = ??? val p2: Path = ??? process(p1, p2.key) <- compile-time-error
- rnikander 5y agoInteresting. Thanks! I've been using a lot of Swift lately, and they have a generic type roadmap that talks about "existential types" and being able to "open" an existential. This looks very similar.
- esarbe 5y agoI don't know about in Swift, but in programming languages in general, existential types are usually a concept different from dependent types.[0] [0] https://stackoverflow.com/questions/292274/what-is-an-existential-type https://stackoverflow.com/questions/292274/what-is-an-existe...