



下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 家庭农场联合经营管理合作协议文本
- 品牌授权许可与分销合作协议
- 未来的路你将怎样走完10篇范文
- 康复医疗服务体系康复康复护理康复设备创新与运营模式研究
- 探讨2025年制造业数据治理在智能制造生产环境监测中的应用与挑战报告
- 《教育统计学》期末考试试卷附答案
- 零售门店数字化运营中的顾客需求挖掘与分析报告
- 鲁教版高中地理必修三第二单元单元复习课件
- 《直线方程的两点式》教学设计
- 妊娠期糖尿病护理查房讲课文档
- 2030年全球甲烷评估基准线报告
- 新品上市引爆计划
- 游资操盘手法与实录
- 肘关节后脱位的健康宣教
- GB/T 43207-2023信息安全技术信息系统密码应用设计指南
- 生活饮用水检验规范(2001)
- 2023年盐山县卫生健康系统事业单位招聘笔试题库及答案解析
- 养老医疗护理员培训培训课件
- DB3301T 0235-2018 城市公共厕所设置标准
- 运输风险防控记录表
- 三类汽车维修管理制度doc-收费标准
评论
0/150
提交评论