首页 > 其他分享 >11-Simple Extensions

11-Simple Extensions

时间:2024-02-01 21:27:06浏览次数:26  
标签:11 Simple t2 t1 let 求值 Extensions type Unit

基本类型 Base Types

A B C 表示基本类型 base types / atomic types 名称,$ A $ 表示基本类型组成的集合

当展示求值的结果时,将省略 λ 抽象体,直接简记为一个 <fun>,比如

λx : B . x
> <fun> : B → B

单位类型 Unit Types

Unit 类型的成员只有 unit

Derived forms 在下一节

Unit 在带副作用的语言中有很重要的作用;主要应用在带副作用的操作的语句(例如赋值语句)

导出形式:序列

对序列中的两个或者多个表达式求值 t1; t2,求值 t1 然后丢掉结果求值 t2

有两种方法去规范地定义序列

The high-level typing and evaluation rules for sequencing can be derived from the abbreviation of t1;t2 as (λx:Unit.t2) t1. This intuitive correspondence is captured more formally by arguing that typing and evaluation both “commute” with the expansion of the abbreviation.

也就是说序列的更高级的类型化和运算可以从后面这个 lambda 形式导出

定理

The advantage of introducing features like sequencing as derived forms rather than as full-fledged language constructs is that we can extend the surface syntax (i.e., the language that the programmer actually uses to write programs) without adding any complexity to the internal language about which theorems such as type safety must be proved.

我们可以扩展表面语法而不使语法的内核复杂化

通配符

Another derived form that will be useful in examples later on is the “wild-card” convention for variable binders. It often happens (for example, in terms created by desugaring sequencing) that we want to write a “dummy” lambda-abstraction in which the parameter variable is not actually used in the body of the abstraction. In such cases, it is annoying to have to explicitly choose a name for the bound variable; instead, we would like to replace it by a wildcard binder, written _. That is, we will write λ_:S.t to abbreviate λx:S.t, where x is some variable not occurring in t.

之前我们写出了一个虚拟的 λ,而囿变量 x 是一个实际上并不在抽象体中的变量,这个时候我们用通配符 _ 指代这种参数变量

归属

t as T 将一种类型 T 归属到给定的项 t

The typing rule T-Ascribe for this construct (cf. Figure 11-3) simply verifies that the ascribed type T is, indeed, the type of t. The evaluation rule E-Ascribe is equally straightforward: it just throws away the ascription, leaving t free to evaluate as usual.

归属的作用有:

  • documentation 使程序容易阅读

  • 让复杂类型便于编写(一种缩写机制),比如:

UU = Unit → Unit

UU 表示 Unit → Unit 的一个缩写

(λf : UU . f unit)(λx : unit . x)

  • 抽象机制 abstraction

let 绑定

OCaml 中已经见过,let 给表达式绑定一个名称;let x = t1 in t2 表示对 t1 求值,在计算 t2 时把 x 绑定为 t1 的结果

let 也可以被表示成一个导出形式:

But notice that the right-hand side of this abbreviation includes the type annotation T1, which does not appear on the left-hand side.

等式左边并不包含 T1 这个类型信息而右边包含

_We discover the needed type annotation simply by calculating the type of t1.

意味着我们要通过类型推断得到 t1 的类型

More formally, what this tells us is that the let constructor is a slightly different sort of derived form than the ones we have seen up till now: we should regard it not as a desugaring transformation on terms, but as a transformation on typing derivations (or, if you prefer, on terms decorated by the typechecker with the results of its analysis) that maps a derivation involving let.

形式上的解释是,let 的导出形式与目前所有的已知的导出形式不同,不是项上的转换,而是类型推导的一个转换:

序偶

注意隐含的求值顺序(从左到右)

元组

记录

标签:11,Simple,t2,t1,let,求值,Extensions,type,Unit
From: https://www.cnblogs.com/sysss-blogs/p/18001361

相关文章

  • Go语言精进之路读书笔记第11条——尽量定义零值可用的类型
    11.1Go类型的零值Go语言规范中关于变量默认值的描述:当通过声明或调用new为变量分配存储空间,或者通过复合文字字面量或调用make创建新值,且不提供显式初始化时,Go会为变量或值提供默认值。Go规范定义的内置原生类型的默认值(零值):所有整型类型:0浮点类型:0.0布尔类型:false字符......
  • Crypto( 11 )
    yxx将两个文件都用010打开,转为二进制下面是异或脚本点击查看代码a='01101100011011110111011001100101011011000110111101110110011001010110110001101111011101100110010101101100011011110111011001100101011011000110111101110110011001010110110001101111011101100110......
  • 洛谷题单指南-暴力枚举-P1149 [NOIP2008 提高组] 火柴棒等式
    原题链接:https://www.luogu.com.cn/problem/P1149题意解读:计算符合A+B=C时,火柴棍数量正好等于n,可以采用枚举A、B,然后计算出C,根据A、B、C计算出所有火柴棍数量,再加上4根加号、等号的,如果与n相等,即为一种合法等式。解题思路:题目的关键在于枚举A、B时,最大值的设定,不能超时。分析......
  • 强化学习无人车训练11
                     ......
  • Spring自带的这11个工具类,真香!
    前言最近有些小伙伴,希望我分享一些好用的工具类,帮他们提升开发效率。今天这篇文章专门跟大家一起总结一下,Spring框架本身自带的一些好用的工具类,希望对你会有所帮助。1Assert很多时候,我们需要在代码中做判断:如果不满足条件,则抛异常。有没有统一的封装呢?其实Spring给我们......
  • C Primer Plus 中文第6版 10.13 第11题
    题目:编写一个程序,声明一个int类型的3*5二维数组,并用合适的值初始化它。该程序打印数组中的值,然后各值翻倍(即是原来的2倍),并显示出各个元素的新值。编写一个函数显示数组的内容,再编写一个函数把各元素的翻倍。这两个函数都以函数名和行数作为参数。分析:写2个函数即可。翻倍函数,用于使......
  • 题解 P6491 [COCI2010-2011#6] ABECEDA
    传送门。分析两个字符大小关系不变,并且具有传递性,我们可以联想到拓扑排序来解决。因此,我们就通过字符串的大小关系,推断出一些字符的大小关系,然后拓扑排序即可。#include<bits/stdc++.h>#include<vector>#include<string>#include<queue>//#defineintlonglongusing......
  • 11.Transform抽象类
    在WPF框架中有一个抽象类叫Transform,它定义了实现二维平面中的转换的功能。它包括旋转(RotateTransform)、缩放(ScaleTransform)、倾斜(SkewTransform)和平移(TranslateTransform)4个子类。它定义如何将点从一个坐标空间映射或转换到另一个坐标空间。此映射由转换Matrix来......
  • 关于Windows11的优化内容 - 进阶者系列 - 学习者系列文章
          这几天无事,想起上次刚重装的Windows11操作系统,对于系统优化的内容想记录一下,以前没写过相关的博文,这次就做个记录吧。对于Windows11,已经出来几年了,相关的设置啥的也有,就是优化方面的软件和设置也有相关的,这次就把笔者这边所有相关的优化工具软件和脚本啥的一并发布......
  • Windows 10 11 安全加固 仅供参考,请查阅资料清楚后使用
    WindowsRegistryEditorVersion5.00;设置密码策略[HKEY_LOCAL_MACHINE\SECURITY\Policies\PasswordPolicy]"MinimumPasswordLength"=dword:00000008"MaximumPasswordAge"=dword:00000030"PasswordComplexity"=dword:00000001"PasswordHi......