User loginNavigation |
archivesConstant Values as TypesThis is probably one of those naive I should first finish the Pierce book kind of questions, but here goes anyway: Are there languages where a constant value, such as 42, can act is its own type? So putting this in real-world terms, in the Cat language I can write the following function with a type annotation: define the_answer : ()->(int) { 42 } However, it seems that I am being too general by saying it returns an int in the type annotation because it always returns 42 (edit: which we could say is a subtype of int). So ... shouldn't the type annotation be: define the_answer : ()->(42) { 42 } So the more general question is: what is good / bad about this? |
Browse archivesActive forum topics |
Recent comments
22 weeks 3 hours ago
22 weeks 7 hours ago
22 weeks 7 hours ago
44 weeks 1 day ago
48 weeks 3 days ago
50 weeks 15 hours ago
50 weeks 15 hours ago
1 year 4 days ago
1 year 5 weeks ago
1 year 5 weeks ago