在Idris中依赖类型的简单演示是Vector,其类型取决于它的值.
我们可以在Python中定义Type Hints.
from typing import List
def append(a: List[int], b: List[int]) -> List[int]:
return a + b
print(append([1, 2], [1, 3, 4]))
Run Code Online (Sandbox Code Playgroud)
那么,我们可以实现一个类型Vect,可以使用如下:
def append(a: Vect[m,t], b: Vect[n,t]) -> Vect[(m+n),t]:
return a + b
Run Code Online (Sandbox Code Playgroud)
m并且n是自然数,t是任何类型的.
我可以写lambda id_Int和id_Boolean显式类型.我可以identity用类型参数编写函数.我可以用类型参数写lambda吗?
fun testFuncInt(f: (Int) -> Int): Int = f(1) + 2
val id_Int = { x: Int -> x }
fun testFuncBoolean(f: (Boolean) -> Boolean): Boolean = !f(false)
val id_Boolean = { x: Boolean -> x }
fun <T> identity(x: T) = x
fun main(args: Array<String>) {
println(testFuncInt(id_Int))
println(testFuncInt(::identity))
println(testFuncBoolean(id_Boolean))
println(testFuncBoolean(::identity))
}
Run Code Online (Sandbox Code Playgroud) TypeScript 的一个函数写成如下:
function propKeyMap(propKey:string):string {
//TODO
}
Run Code Online (Sandbox Code Playgroud)
在propKey不能为 ""(空字符串)。我们可以写一个不包含空字符串的类型吗?
java 10.0.1 2018-04-171.2.414.7如果我们可以使用拼图模块系统会更好
我正在使用 Dockerfile 构建 docker 镜像:
FROM centos:centos7.1.1503
MAINTAINER foo <foo@bar.com>
ENV TZ "Asia/Shanghai"
ENV TERM xterm
RUN \
yum update -y && \
yum install -y epel-release &&\
yum update -y && \
yum install -y curl wget tar bzip2 unzip vim-enhanced passwd sudo yum-utils hostname net-tools rsync man && \
yum install -y gcc gcc-c++ git make automake cmake patch logrotate python-devel libpng-devel libjpeg-devel && \
yum install -y pwgen python-pip && \
yum clean all
Run Code Online (Sandbox Code Playgroud)
它显示如下错误:
Error: libselinux …Run Code Online (Sandbox Code Playgroud) 我想写一个ProptyDontHaveChildren没有被调用的属性的接口children
type ChildrenType = Array<number>
interface ProptyDontHaveChildren {
// doesn't have property called children
[index: string]: string;
}
interface WithChildren {
children: ChildrenType
}
type IntersectionType = ProptyDontHaveChildren & WithChildren;
function createElement(type: string, props: ProptyDontHaveChildren, ...children: ChildrenType ) {
const newProps:IntersectionType = { children: children, ...props }
//TODO ...
}
Run Code Online (Sandbox Code Playgroud)
如何定义一个在 TypeScript 中没有某些属性的接口?
replicate(n:Int,x:T):List<T> 是一个长度为n的列表,其中x是每个元素的值.
我写了一个可变版本复制如下:
fun <T> mutableReplicate(n:Int, x:T) : MutableList<T>{
val xs = mutableListOf<T>()
for (i in 1..n){
xs.add(x)
}
return xs
}
Run Code Online (Sandbox Code Playgroud)
在Kotlin中是否有任何bulid-in immutable replicate功能?
如何在Kotlin中为自己写一个不可变的复制函数?
grep、egrep、fgrep、rgrep、pgrep的说明如下:
描述
grep、egrep、fgrep、rgrep、pgrep - 是类 Unix 操作系统中的命令,用于打印与模式匹配的行。grep 在指定的输入文件中搜索包含与给定模式匹配的行。默认情况下,它打印匹配的行。
此外,变体程序egrep、fgrep 和rgrep 分别与grep -E、grep -F 和grep -r 相同。这些变体已被弃用,但提供它们是为了向后兼容。
为什么egrep、fgrep 和 rgrep的这些变体已被弃用?