下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Programming LanguagesDan GrossmanPolymorphic Types and Functions As ArgumentsThe key pointHigher-order functions are often so “generic” and “reusable” that they have polymorphic types, i.e., types with type variablesBut there are higher-order functions that are not polymorphicAnd there are non-highe
2、r-order (first-order) functions that are polymorphicAlways a good idea to understand the type of a function, especially a higher-order function2Dan Grossman, Programming LanguagesTypesval n_times : (a - a) * int * a - aSimpler but less useful: (int - int) * int * int - intTwo of our examples instant
3、iated a with intOne of our examples instantiated a with int listThis polymorphism makes n_times more usefulType is inferred based on how arguments are used (later lecture) Describes which types must be exactly something (e.g., int) and which can be anything but the same (e.g., a)3Dan Grossman, Progr
4、amming Languagesfun n_times (f,n,x) = if n=0 then x else f (n_times(f,n-1,x)Polymorphism and higher-order functionsMany higher-order functions are polymorphic because they are so reusable that some types, “can be anything”But some polymorphic functions are not higher-orderExample: len : a list - intAnd some higher-order functions are not polymorphicExample: times_until_0 : (int - int) * int - int4Dan Grossman, Programming Languagesfun times_until_0 (f,x) = if x=0 then 0
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年大学英语教育(英语教学)试题及答案
- 5.1《分数的再认识(一)》(教学课件)-五年级 数学上册 北师大版
- 工程施工员工安全培训课件
- 制氧设备维修培训课件
- 制剂车间员工培训课件
- 工程安全生产教育培训课件
- 工程安全培训标语课件
- 期末模拟试卷及答案-2025-2026学年人教版小学数学五年级上册
- 手术AI数据质量的控制标准
- 安全风险管控与隐患排查治理双重预防机制建设培训试题及答案
- 特殊食品产业现状与发展趋势
- 心外科护理教学课件
- DB64∕680-2025 建筑工程安全管理规程
- 海洋能经济性分析-洞察及研究
- 2025年中国MINI-LED市场竞争格局及投资战略规划报告
- 四年级上册数学脱式计算大全500题及答案
- 分位数因子增广混频分位数回归模型构建及应用研究
- DB35T 2169-2024仲裁庭数字化建设规范
- 对公账户协议书范本
- 职业暴露考试试题及答案
- DB61-T 1843-2024 酸枣种植技术规范
评论
0/150
提交评论