小编Maë*_*lan的帖子

如何检查mongo db是否在Mac上运行?

我已经MongoDB在我的Mac上安装了几天,并且不确定我是如何安装的,但是现在如何检查MongoDB我的系统是否正常运行?

macos installation mongodb osx-yosemite

33
推荐指数
2
解决办法
3万
查看次数

“a.”和“type a.”有什么区别以及何时使用它们?

OCaml 对于多态类型注释有几种不同的语法:

\n
let f :         \'a -> \'a = \xe2\x80\xa6 (* Isn\xe2\x80\x99t this one already polymorphic? (answer: NO) *)\nlet f : \'a.     \'a -> \'a = \xe2\x80\xa6\nlet f : type a.  a ->  a = \xe2\x80\xa6\n
Run Code Online (Sandbox Code Playgroud)\n

当使用奇特的代数数据类型(通常是 GADT)时,我们经常会看到它们,它们似乎是必要的。

\n

这些语法有什么区别?何时以及为何必须使用每一项?

\n

polymorphism ocaml type-inference algebraic-data-types

17
推荐指数
3
解决办法
1726
查看次数

OCaml,`type `!+'at` 中 `!+` 的含义

我目前正在学习 OCaml,尤其是函子。map.mli我从标准库中查看,在第 70 行左右,有:

type key
(** The type of the map keys. *)

type !+'a t
(** The type of maps from type [key] to type ['a]. *)

val empty: 'a t
(** The empty map. *)
Run Code Online (Sandbox Code Playgroud)

我知道这key是映射中使用的密钥的类型(或者更确切地说是它的签名,因为我们在文件中.mli),并且'a t是映射本身的(多态/抽象)类型。不过我想知道!+有什么用。我尝试寻找一些有关它的文档,但不幸的是没有找到任何文档。

如果可能的话,我希望得到有关此问题的解释和/或相关文档/教程的链接。

提前致谢。

ocaml types signature covariance type-declaration

13
推荐指数
1
解决办法
1246
查看次数

嵌套上下文中的显式多态注释

在下面的代码中,我不确定我是否理解为什么_nested2.

这是否意味着只有顶级定义才能概括其推断类型以匹配显式多态签名?

let toplevel1 : 'a. 'a -> int = (fun _ -> 0)
let toplevel2 : 'a. 'a -> int = (fun (_ : 'a) -> 0)

let nest1 =
  let _nested1 : 'a. 'a -> int = (fun _ -> 0) in 0

let nest2 =
  let _nested2 : 'a. 'a -> int = (fun (_ : 'a) -> 0) in 0
(*                               ^^^^^^^^^^^^^^^^^^^
   Error: This definition has type 'a -> int which is less general …
Run Code Online (Sandbox Code Playgroud)

polymorphism ocaml types type-inference let

5
推荐指数
1
解决办法
103
查看次数

参数和类成员之间的区别

我是 Coq 的新手,想知道以下内容之间有什么区别:

Class test (f g: nat -> nat) := {
  init:   f 0 = 0 /\ g 0 = 0;
  output: ...another proposition about f and g...;
}.
Run Code Online (Sandbox Code Playgroud)

Class test := {
  f: nat -> nat;
  g: nat -> nat;
  init:   f 0 = 0 /\ g 0 = 0;
  output: ...another proposition about f and g...;
}.
Run Code Online (Sandbox Code Playgroud)

有人能提供解释吗?

record typeclass coq dependent-type

4
推荐指数
2
解决办法
100
查看次数

有理数的“小于”在 Coq 中可以判定吗?

在 Coq 标准库中,“小于”关系对于自然数 ( lt_dec) 和整数 ( Z_lt_dec) 是可判定的。然而,当我搜索 ( Search ({ _ _ _ } + {~ _ _ _ })) 时,我找不到 aQ_le_decQle_dec的有理数,只能Qeq_dec找到可判定的相等性。

这是因为“小于”关系对于 Coq 中的有理数来说是不可判定的吗?或者它是可以决定的,但决策过程没有在标准库中实现?

comparison rational-number coq decidable

3
推荐指数
1
解决办法
162
查看次数

使用 scanf 在非空白分隔符上分割字符串

我的目标是扫描包含冒号作为除法的字符串,并将其两个部分保存在一个元组中。
例如:

input: "a:b"
output: ("a", "b")
Run Code Online (Sandbox Code Playgroud)

到目前为止,我的方法不断收到错误消息:
“scanf:字符号 9 处输入错误:寻找 ':',找到 '\n'”。

 Scanf.bscanf Scanf.Scanning.stdin "%s:%s" (fun x y -> (x,y));;
Run Code Online (Sandbox Code Playgroud)

此外,我的方法适用于整数,我很困惑为什么它不适用于字符串。

Scanf.bscanf Scanf.Scanning.stdin "%d:%d" (fun x y -> (x,y));;
4:3
- : int * int = (4, 3)
Run Code Online (Sandbox Code Playgroud)

string io ocaml split scanf

3
推荐指数
1
解决办法
339
查看次数

模式匹配中“as”的范围

给定一个从列表中删除连续重复项的函数

let rec compress l =
  match l with
  | [] -> []
  | [x] -> [x]
  | x :: (y :: _ as t) -> if x = y then compress t else x :: compress t;;
Run Code Online (Sandbox Code Playgroud)

产生正确的结果

compress ["a"; "a";"b";"c";"c"] ;;
- : string list = ["a"; "b"; "c"]
Run Code Online (Sandbox Code Playgroud)

但如果x :: (y :: _ as t)我改为x :: (y :: t),那么我会得到不正确的结果

compress ["a"; "a";"b";"c";"c"] ;;
- : string list = ["b"; "c"]
Run Code Online (Sandbox Code Playgroud)

这里发生了什么 ?我无法理解声明如何_ …

ocaml pattern-matching

2
推荐指数
1
解决办法
63
查看次数

是否可以在 Coq 中声明类型相关的表示法?

由于Coq有强大的类型推断算法,我想知道我们是否可以根据Notation的变量“重载”不同的重写符号。

作为一个例子,我将借用我在 Coq 中形式化类型化语言语义的一篇作品。在这种形式化中,我有类型对和表达式对,并且我想对它们各自的构造函数使用相同的符号:{ _ , _ }

Inductive type: Type := ... | tpair: type -> type -> type | ...
Inductive expr: Type := ... | epair: expr -> expr -> expr | ... 

Notation "{ t1 , t2 }" := tpair t1 t2
Notation "{ e1 , e2 }" := epair e1 e2
Run Code Online (Sandbox Code Playgroud)

我知道最后一个语句会引发错误,因为符号已经定义;如果有人考虑过围绕它进行欺骗,或者是否有另一种“官方”方式来做到这一点,我将不胜感激。

overloading notation coq

2
推荐指数
1
解决办法
167
查看次数