他の言語では、依存型のようなものを使ってさらに進められるよ。例えば、get_elem_at_index(array, index)のようなものは、配列の範囲外のインデックスを持つことができないってことを、コンパイル時に静的にチェックできるんだ。しかも、配列の長さを事前に知らなくてもね。「Idrisでは、長さインデックス付きベクターは Vect n a(長さ n が型に含まれる)で、長さ n への有効なインデックスは Fin n('n より厳密に小さい自然数')だよ。」分割して無限やマイナス無限になる可能性のある割り算でも同じようなトリックが使えるし、型チェックを防ぐための微妙な意味合いもあるんだ。例えば、高次型や関数においてね。
これ、最近のStroustrupの発表を思い出すな。C++で必要なところで整数変換を自動的に検証するためにコンセプトを使うってやつ。https://www.stroustrup.com/Concept-based-GP.pdf { Number ii = 0; Number cc = '0'; ii = 2; // OK ii = -2; // throws cc = i; // OK もし i が cc の範囲内なら cc = -17; // char が符号付きなら OK; そうでなければ throws cc = 1234; // char が8ビットなら throws }
最近の関連情報: Parse, Don't Validate (2019) - https://news.ycombinator.com/item?id=46960392 - 2026年2月 (172件のコメント) こちらも: Parse, Don’t Validate – 一部Cの安全性ヒント - https://news.ycombinator.com/item?id=44507405 - 2025年7月 (73件のコメント) Parse, Don't Validate (2019) - https://news.ycombinator.com/item?id=41031585 - 2024年7月 (102件のコメント) Parse, don't validate (2019) - https://news.ycombinator.com/item?id=35053118 - 2023年3月 (219件のコメント) Parse, Don't Validate (2019) - https://news.ycombinator.com/item?id=27639890 - 2021年6月 (270件のコメント) Parsix: Parse Don't Validate - https://news.ycombinator.com/item?id=27166162 - 2021年5月 (107件のコメント) Parse, Don’t Validate - https://news.ycombinator.com/item?id=21476261 - 2019年11月 (230件のコメント) Parse, Don't Validate - https://news.ycombinator.com/item?id=21471753 - 2019年11月 (4件のコメント) (追記: これらのリンクは好奇心旺盛な読者のために載せてるだけで、批判の意図はないよ!こういうことを言うと、みんなが勘違いしちゃうことがあるからね)