Type Error
释义 (Definition)
Type error:类型错误。在编程中指把某种数据类型当成另一种不兼容的类型来使用,导致程序在编译期或运行期报错(例如把字符串当作数字相加、对整数使用只适用于列表的操作等)。
发音 (Pronunciation, IPA)
/taɪp ˈerər/
例句 (Examples)
I got a type error when I tried to add a number to a string.
当我试图把数字和字符串相加时,出现了类型错误。
Because the function expects a list but received a dictionary, the program throws a type error at runtime.
因为这个函数需要的是列表却收到了字典,程序在运行时抛出了类型错误。
词源 (Etymology)
type 原指“类型/种类”(来自希腊语 typos,意为“印记、模子、范式”),在计算机领域引申为“数据类型”;error 来自拉丁语 error,意为“错误、偏离”。合起来 type error 就是“与类型相关的错误”,强调错误的根源在于类型不匹配或类型使用不当。
相关词 (Related Words)
文学与经典作品中的用例 (Literary / Notable Works)
- Types and Programming Languages(Benjamin C. Pierce)——讨论类型系统时频繁使用 type error 来指代程序被判定“不良类型”而无法通过检查的情况。
- *Structure and Interpretation of Computer Programs (SICP)*(Harold Abelson & Gerald Jay Sussman)——在讲解抽象与过程应用时,会提到因对象类型不符合预期而产生的错误(常以“type error/错误类型使用”来描述)。
- Programming Languages: Application and Interpretation(Shriram Krishnamurthi)——在解释解释器与类型检查时,常用 type error 作为示例错误类别。