免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3501 | 回复: 0
打印 上一主题 下一主题

OCaml function dictionary [复制链接]

论坛徽章:
1
IT运维版块每日发帖之星
日期:2015-12-20 06:20:00
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-10-22 14:56 |只看该作者 |倒序浏览
这是Cornell Ocaml course的一个function dictionary,谁能给解释一下该怎么用吗?我怎么感觉那个make定义的不对是不
dictionary
  1. module FunctionDict : DICTIONARY =
  2.   struct
  3.     type key = string
  4.     type 'a dict = string -> 'a
  5.     (* The function f represents the mapping in which x is mapped to
  6.      * (f x), except for x that are not in the mapping, in which case
  7.      * f raises NotFound.
  8.      *)
  9.     exception NotFound
  10.     let make () = fun _ -> raise NotFound
  11.     let lookup (d : 'a dict) (key : string) : 'a = d key
  12.     let insert (d : 'a dict) (k : key) (x : 'a) : 'a dict =
  13.       fun k' -> if k = k' then x else d k'
  14.     let map (f : 'a -> 'b) (d : 'a dict) = fun k -> f (d k)
  15.   end
复制代码


您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP