我有一个像这样的值的夹具:
product_four:
id: 4
application_id: 1
title: "oldtitle"
deleted_at: ~
Run Code Online (Sandbox Code Playgroud)
设置postgresql数据库进行测试.但我无法弄清楚如何将deleted_at字段设置为NULL而不是[empty].我试过了:
deleted_at: :null
deleted_at: <%= nil %>
deleted_at: ~
deleted_at: NULL
Run Code Online (Sandbox Code Playgroud)
可能还有几个,没有运气.线索无能为力?
编辑:对不起大家,我以为我的小例子已经完成,结果不是。 我做了一个新的,真的应该是!
一旦我使用格式化程序作为 Scanf 或 Printf 函数的参数,格式化程序类型就会分别绑定到输入或输出通道。有没有办法让函数采用格式化程序(或字符串)并将其用作打印和读取的格式化程序?
let fmt = format_of_string "%d,%d";;
Scanf.sscanf "2,2" fmt (fun x y -> x,y);;
fmt;;
Run Code Online (Sandbox Code Playgroud)
给
- : (int -> int -> int * int, Scanf.Scanning.scanbuf, '_a, (int -> int -> int * int) -> int * int, (int -> int -> int * int) -> int * int, int * int) format6 = <abstr>
Run Code Online (Sandbox Code Playgroud)
这意味着后续Printf.printf fmt 1 2;;会给出类型错误。这适用于我尝试过的每种功能format_of_string和Scanf.format_from_string类似功能的组合。
例子:
module Thing = struct
(* Just …Run Code Online (Sandbox Code Playgroud) 我似乎在这里有一个cat-in-a-box类问题以下代码应该,给定一个键和一个哈希表,返回对应于该键的值,如果该键不存在于映射中则为错误:
(defun get-graph-node (key graph)
(let ((result (gethash key graph)))
(if (nth-value 1 result)
(nth-value 0 result)
(error "no node matches the key"))))
Run Code Online (Sandbox Code Playgroud)
在大多数情况下它确实如此,但我有这种奇怪的情况:
(gethash 0 *g*)
Run Code Online (Sandbox Code Playgroud)
回报
#S(GRAPH-NODE$
:DATA "("$
:EDGES (#S(GRAPH-NODE :DATA "b" :EDGES NIL)$
#S(GRAPH-NODE :DATA "a" :EDGES NIL)))
T
Run Code Online (Sandbox Code Playgroud)
但
(get-graph-node 0 *g*)
Run Code Online (Sandbox Code Playgroud)
表示get-graph-node中定义的错误
检查*g*给我这个:
Count: 5
Size: 16
Test: EQL
Rehash size: 1.5
Rehash threshold: 1.0
[clear hashtable]
Contents:
0 = #S(GRAPH-NODE :DATA "(" :EDGES (#S(GRAPH-NODE :DATA "b" :EDGES NIL) #S(GRAPH-NODE :DATA "a" :EDGES NIL))) …Run Code Online (Sandbox Code Playgroud) 除了可读性和失去一般性之外,以下定义有什么问题:
maxPlusOne :: (Ord a, Num a) => a -> a -> a
maxPlusOne = (1+) . max
Run Code Online (Sandbox Code Playgroud)
编译器会抱怨它不能从中推断Num (a -> a)出来+.但在我看来它需要的是什么Num a => a -> a,这正是它的类型(1+).
这是错误:
<interactive>:5:52:
Could not deduce (Num (a -> a)) arising from a use of ‘+’
from the context (Ord a, Num a)
Run Code Online (Sandbox Code Playgroud)