Hacker News new | past | comments | ask | show | jobs | submit login

C++ and Scala don't really have dependent typing, but rather a single feature that is typical of dependent typing. That is: type-level values of any type.



Both Scala and C++ have a set of type-system features that when combined allow you create functions whose return type can depend on the value of the passed argument. For a good step by step of how to do this in Scala see here[1], and a (unfortunately less in depth) C++ example is here[2].

[1]: http://gigiigig.github.io/tlp-step-by-step/dependent-types.h...

[2]: https://www.reddit.com/r/cpp/comments/2tilfw/dependent_typin...


I am not familiar enough with Scala, but the C++ example certainly does not seem like dependent types.

Which function in there do you consider to have a return type that depends on the value of the input?


Doesn't C++ only have type-level integers (as template parameters)? Are you referring to something else?


I haven't used C++ in years. That may be true.

In that case, it may be even more puzzling to claim that C++ has dependent types.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: