Scala与单位一起

时间:2016-08-26 03:47:20

标签: scala

我很好奇这样做的正确方法。假设我想通过方法发出成功或失败的信号。这是否可以接受,如果在成功的情况下除了成功之外没有我想说的话?

def fn(): Either[Throwable, Unit]

从这个方法返回Right()的正确方法是什么?显然只是返回Right()给出了一个弃用警告(通过插入()修改参数列表已被弃用。)

我也可以做Option [Throwable],但这并不符合我如何阅读Option的精神。或者可能返回scala.util.Try的结果并评估成功/失败?

- 在弃用警告上,仅供参考。

Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101).
Type in expressions for evaluation. Or try :help.

scala> def fn:Either[Throwable, Unit] = { Right() }
<console>:11: warning: Adaptation of argument list by inserting () has been deprecated: this is unlikely to be what you want.
        signature: Right.apply[A, B](b: B): scala.util.Right[A,B]
  given arguments: <none>
 after adaptation: Right((): Unit)
       def fn:Either[Throwable, Unit] = { Right() }
                                               ^
fn: Either[Throwable,Unit]

2 个答案:

答案 0 :(得分:5)

您可以使用Unit作为类型并返回()

def fn(): Either[Throwable, Unit] = Right(())

答案 1 :(得分:1)

我想说这取决于您正在寻找的API类型。

/bin/bash /home/hamid/xhprof-0.9.2/extension/libtool --mode=compile cc -I. -I/home/hamid/xhprof-0.9.2/extension -DPHP_ATOM_INC -I/home/hamid/xhprof-0.9.2/extension/include -I/home/hamid/xhprof-0.9.2/extension/main -I/home/hamid/xhprof-0.9.2/extension -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/hamid/xhprof-0.9.2/extension/xhprof.c -o xhprof.lo libtool: compile: cc -I. -I/home/hamid/xhprof-0.9.2/extension -DPHP_ATOM_INC -I/home/hamid/xhprof-0.9.2/extension/include -I/home/hamid/xhprof-0.9.2/extension/main -I/home/hamid/xhprof-0.9.2/extension -I/usr/include/php/20151012 -I/usr/include/php/20151012/main -I/usr/include/php/20151012/TSRM -I/usr/include/php/20151012/Zend -I/usr/include/php/20151012/ext -I/usr/include/php/20151012/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /home/hamid/xhprof-0.9.2/extension/xhprof.c -fPIC -DPIC -o .libs/xhprof.o In file included from /usr/include/php/20151012/main/php.h:34:0, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/main/php_config.h:2458:0: warning: "_GNU_SOURCE" redefined #define _GNU_SOURCE 1 ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:24:0: note: this is the location of the previous definition # define _GNU_SOURCE ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:236:1: warning: ‘visibility’ attribute ignored [-Wattributes] static ZEND_DLEXPORT void (*_zend_execute) (zend_op_array *ops TSRMLS_DC); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:240:28: warning: ‘visibility’ attribute ignored [-Wattributes] int ret TSRMLS_DC); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_init_profiler_state’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:625:5: warning: implicit declaration of function ‘FREE_ZVAL’ [-Wimplicit-function-declaration] FREE_ZVAL(hp_globals.stats_count); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:627:3: warning: implicit declaration of function ‘MAKE_STD_ZVAL’ [-Wimplicit-function-declaration] MAKE_STD_ZVAL(hp_globals.stats_count); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:635:5: warning: implicit declaration of function ‘restore_cpu_affinity’ [-Wimplicit-function-declaration] restore_cpu_affinity(&hp_globals.prev_mask); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:639:3: warning: implicit declaration of function ‘bind_to_cpu’ [-Wimplicit-function-declaration] bind_to_cpu((int) (rand() % hp_globals.cpu_num)); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_get_function_name’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:895:21: error: ‘zend_execute_data {aka struct _zend_execute_data}’ has no member named ‘function_state’ curr_func = data->function_state.function; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:898:10: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] func = curr_func->common.function_name; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:909:13: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] cls = curr_func->common.scope->name; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:910:22: error: ‘zend_execute_data {aka struct _zend_execute_data}’ has no member named ‘object’ } else if (data->object) { ^ In file included from /usr/include/php/20151012/Zend/zend.h:31:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /home/hamid/xhprof-0.9.2/extension/xhprof.c:911:28: error: ‘zend_execute_data {aka struct _zend_execute_data}’ has no member named ‘object’ cls = Z_OBJCE(*data->object)->name; ^ /usr/include/php/20151012/Zend/zend_types.h:530:26: note: in definition of macro ‘Z_OBJ’ #define Z_OBJ(zval) (zval).value.obj ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:911:15: note: in expansion of macro ‘Z_OBJCE’ cls = Z_OBJCE(*data->object)->name; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:930:34: error: ‘znode_op {aka const union _znode_op}’ has no member named ‘u’ curr_op = data->opline->op2.u.constant.value.lval; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:963:41: warning: passing argument 1 of ‘hp_get_base_filename’ from incompatible pointer type [-Wincompatible-pointer-types] filename = hp_get_base_filename((curr_func->op_array).filename); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:856:14: note: expected ‘char *’ but argument is of type ‘zend_string * {aka struct _zend_string *}’ static char *hp_get_base_filename(char *filename) { ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_inc_count’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1043:26: warning: passing argument 2 of ‘zend_hash_find’ from incompatible pointer type [-Wincompatible-pointer-types] if (zend_hash_find(ht, name, strlen(name) + 1, &data) == SUCCESS) { ^ In file included from /usr/include/php/20151012/Zend/zend.h:36:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_hash.h:154:30: note: expected ‘zend_string * {aka struct _zend_string *}’ but argument is of type ‘char *’ ZEND_API zval* ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1043:7: error: too many arguments to function ‘zend_hash_find’ if (zend_hash_find(ht, name, strlen(name) + 1, &data) == SUCCESS) { ^ In file included from /usr/include/php/20151012/Zend/zend.h:36:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_hash.h:154:30: note: declared here ZEND_API zval* ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key); ^ In file included from /usr/include/php/20151012/Zend/zend.h:31:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1044:30: warning: implicit declaration of function ‘Z_LVAL_PP’ [-Wimplicit-function-declaration] ZVAL_LONG(*(zval**)data, Z_LVAL_PP((zval**)data) + count); ^ /usr/include/php/20151012/Zend/zend_types.h:610:19: note: in definition of macro ‘ZVAL_LONG’ Z_LVAL_P(__z) = l; \ ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_hash_lookup’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1067:26: warning: passing argument 2 of ‘zend_hash_find’ from incompatible pointer type [-Wincompatible-pointer-types] if (zend_hash_find(ht, symbol, strlen(symbol) + 1, &data) == SUCCESS) { ^ In file included from /usr/include/php/20151012/Zend/zend.h:36:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_hash.h:154:30: note: expected ‘zend_string * {aka struct _zend_string *}’ but argument is of type ‘char *’ ZEND_API zval* ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1067:7: error: too many arguments to function ‘zend_hash_find’ if (zend_hash_find(ht, symbol, strlen(symbol) + 1, &data) == SUCCESS) { ^ In file included from /usr/include/php/20151012/Zend/zend.h:36:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_hash.h:154:30: note: declared here ZEND_API zval* ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_sample_stack’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1131:21: error: macro "add_assoc_string" passed 4 arguments, but takes just 3 1); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1128:3: error: ‘add_assoc_string’ undeclared (first use in this function) add_assoc_string(hp_globals.stats_count, ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1128:3: note: each undeclared identifier is reported only once for each function it appears in /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_execute_internal’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1639:43: error: ‘zend_execute_data {aka struct _zend_execute_data}’ has no member named ‘op_array’ func = hp_get_function_name(current_data->op_array TSRMLS_CC); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1623:21: warning: initialization discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] #define EX(element) ((execute_data)->element) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1647:23: note: in expansion of macro ‘EX’ zend_op *opline = EX(opline); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1623:36: error: ‘zend_execute_data {aka struct _zend_execute_data}’ has no member named ‘function_state’ #define EX(element) ((execute_data)->element) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1648:33: note: in expansion of macro ‘EX’ ((zend_internal_function *) EX(function_state).function)->handler( ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1624:25: error: ‘temp_variable’ undeclared (first use in this function) #define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset)) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1650:24: note: in expansion of macro ‘EX_T’ EX_T(opline->result.u.var).var.ptr, ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1624:40: error: expected expression before ‘)’ token #define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset)) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1650:24: note: in expansion of macro ‘EX_T’ EX_T(opline->result.u.var).var.ptr, ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1623:36: error: ‘zend_execute_data {aka struct _zend_execute_data}’ has no member named ‘Ts’ #define EX(element) ((execute_data)->element) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1624:51: note: in expansion of macro ‘EX’ #define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset)) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1650:24: note: in expansion of macro ‘EX_T’ EX_T(opline->result.u.var).var.ptr, ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1623:36: error: ‘zend_execute_data {aka struct _zend_execute_data}’ has no member named ‘function_state’ #define EX(element) ((execute_data)->element) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1651:24: note: in expansion of macro ‘EX’ EX(function_state).function->common.return_reference ? ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1624:40: error: expected expression before ‘)’ token #define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset)) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1652:25: note: in expansion of macro ‘EX_T’ &EX_T(opline->result.u.var).var.ptr:NULL, ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1623:36: error: ‘zend_execute_data {aka struct _zend_execute_data}’ has no member named ‘Ts’ #define EX(element) ((execute_data)->element) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1624:51: note: in expansion of macro ‘EX’ #define EX_T(offset) (*(temp_variable *)((char *) EX(Ts) + offset)) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1652:25: note: in expansion of macro ‘EX_T’ &EX_T(opline->result.u.var).var.ptr:NULL, ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1623:36: error: ‘zend_execute_data {aka struct _zend_execute_data}’ has no member named ‘object’ #define EX(element) ((execute_data)->element) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1653:24: note: in expansion of macro ‘EX’ EX(object), ret TSRMLS_CC); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_compile_file’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1683:35: warning: passing argument 1 of ‘hp_get_base_filename’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers] filename = hp_get_base_filename(file_handle->filename); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:856:14: note: expected ‘char *’ but argument is of type ‘const char *’ static char *hp_get_base_filename(char *filename) { ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_begin’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1722:19: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] _zend_execute = zend_execute; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1723:19: error: lvalue required as left operand of assignment zend_execute = hp_execute; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1726:28: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] _zend_execute_internal = zend_execute_internal; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1731:29: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] zend_execute_internal = hp_execute_internal; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_stop’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1796:25: error: lvalue required as left operand of assignment zend_execute = _zend_execute; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1797:25: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types] zend_execute_internal = _zend_execute_internal; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_zval_at_key’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1823:13: error: ‘zval {aka struct _zval_struct}’ has no member named ‘type’ if (values->type == IS_ARRAY) { ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1829:28: warning: passing argument 2 of ‘zend_hash_find’ from incompatible pointer type [-Wincompatible-pointer-types] if (zend_hash_find(ht, key, len, (void**)&value) == SUCCESS) { ^ In file included from /usr/include/php/20151012/Zend/zend.h:36:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_hash.h:154:30: note: expected ‘zend_string * {aka struct _zend_string *}’ but argument is of type ‘char *’ ZEND_API zval* ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1829:9: error: too many arguments to function ‘zend_hash_find’ if (zend_hash_find(ht, key, len, (void**)&value) == SUCCESS) { ^ In file included from /usr/include/php/20151012/Zend/zend.h:36:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_hash.h:154:30: note: declared here ZEND_API zval* ZEND_FASTCALL zend_hash_find(const HashTable *ht, zend_string *key); ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: In function ‘hp_strings_in_zval’: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1853:13: error: ‘zval {aka struct _zval_struct}’ has no member named ‘type’ if (values->type == IS_ARRAY) { ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1873:47: warning: passing argument 2 of ‘zend_hash_get_current_key_ex’ from incompatible pointer type [-Wincompatible-pointer-types] type = zend_hash_get_current_key_ex(ht, &str, &len, &idx, 0, NULL); ^ In file included from /usr/include/php/20151012/Zend/zend.h:36:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_hash.h:168:30: note: expected ‘zend_string ** {aka struct _zend_string **}’ but argument is of type ‘char **’ ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, HashPosi ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1873:53: warning: passing argument 3 of ‘zend_hash_get_current_key_ex’ from incompatible pointer type [-Wincompatible-pointer-types] type = zend_hash_get_current_key_ex(ht, &str, &len, &idx, 0, NULL); ^ In file included from /usr/include/php/20151012/Zend/zend.h:36:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_hash.h:168:30: note: expected ‘zend_ulong * {aka long unsigned int *}’ but argument is of type ‘uint * {aka unsigned int *}’ ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, HashPosi ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1873:59: warning: passing argument 4 of ‘zend_hash_get_current_key_ex’ from incompatible pointer type [-Wincompatible-pointer-types] type = zend_hash_get_current_key_ex(ht, &str, &len, &idx, 0, NULL); ^ In file included from /usr/include/php/20151012/Zend/zend.h:36:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_hash.h:168:30: note: expected ‘HashPosition * {aka unsigned int *}’ but argument is of type ‘ulong * {aka long unsigned int *}’ ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, HashPosi ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1873:14: error: too many arguments to function ‘zend_hash_get_current_key_ex’ type = zend_hash_get_current_key_ex(ht, &str, &len, &idx, 0, NULL); ^ In file included from /usr/include/php/20151012/Zend/zend.h:36:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_hash.h:168:30: note: declared here ZEND_API int ZEND_FASTCALL zend_hash_get_current_key_ex(const HashTable *ht, zend_string **str_index, zend_ulong *num_index, HashPosi ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1876:58: error: macro "zend_hash_get_current_data" passed 2 arguments, but takes just 1 if ((zend_hash_get_current_data(ht, (void**)&data) == SUCCESS) && ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1876:14: error: ‘zend_hash_get_current_data’ undeclared (first use in this function) if ((zend_hash_get_current_data(ht, (void**)&data) == SUCCESS) && ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1877:13: warning: implicit declaration of function ‘Z_TYPE_PP’ [-Wimplicit-function-declaration] Z_TYPE_PP(data) == IS_STRING && ^ In file included from /usr/include/string.h:630:0, from /usr/include/php/20151012/main/php_config.h:2517, from /usr/include/php/20151012/main/php.h:34, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: warning: implicit declaration of function ‘Z_STRVAL_PP’ [-Wimplicit-function-declaration] strcmp(Z_STRVAL_PP(data), ROOT_SYMBOL)) { /* do not ignore "main" */ ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: warning: passing argument 1 of ‘__builtin_strlen’ makes pointer from integer without a cast [-Wint-conversion] strcmp(Z_STRVAL_PP(data), ROOT_SYMBOL)) { /* do not ignore "main" */ ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: note: expected ‘const char *’ but argument is of type ‘int’ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: warning: passing argument 1 of ‘__builtin_strcmp’ makes pointer from integer without a cast [-Wint-conversion] strcmp(Z_STRVAL_PP(data), ROOT_SYMBOL)) { /* do not ignore "main" */ ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: note: expected ‘const char *’ but argument is of type ‘int’ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: warning: passing argument 1 of ‘__builtin_strlen’ makes pointer from integer without a cast [-Wint-conversion] strcmp(Z_STRVAL_PP(data), ROOT_SYMBOL)) { /* do not ignore "main" */ ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: note: expected ‘const char *’ but argument is of type ‘int’ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: warning: passing argument 1 of ‘__builtin_strcmp’ makes pointer from integer without a cast [-Wint-conversion] strcmp(Z_STRVAL_PP(data), ROOT_SYMBOL)) { /* do not ignore "main" */ ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: note: expected ‘const char *’ but argument is of type ‘int’ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: warning: passing argument 1 of ‘__builtin_strcmp’ makes pointer from integer without a cast [-Wint-conversion] strcmp(Z_STRVAL_PP(data), ROOT_SYMBOL)) { /* do not ignore "main" */ ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: note: expected ‘const char *’ but argument is of type ‘int’ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: warning: passing argument 1 of ‘__builtin_strcmp’ makes pointer from integer without a cast [-Wint-conversion] strcmp(Z_STRVAL_PP(data), ROOT_SYMBOL)) { /* do not ignore "main" */ ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1878:20: note: expected ‘const char *’ but argument is of type ‘int’ In file included from /usr/include/php/20151012/Zend/zend.h:33:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_alloc.h:172:35: warning: passing argument 1 of ‘_estrdup’ makes pointer from integer without a cast [-Wint-conversion] #define estrdup(s) _estrdup((s) ZEND_FILE_LINE_CC ZEND_FILE_LINE_EMPTY_CC) ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1879:24: note: in expansion of macro ‘estrdup’ result[ix] = estrdup(Z_STRVAL_PP(data)); ^ In file included from /usr/include/php/20151012/Zend/zend.h:33:0, from /usr/include/php/20151012/main/php.h:36, from /home/hamid/xhprof-0.9.2/extension/xhprof.c:27: /usr/include/php/20151012/Zend/zend_alloc.h:84:31: note: expected ‘const char *’ but argument is of type ‘int’ ZEND_API char* ZEND_FASTCALL _estrdup(const char *s ZEND_FILE_LINE_DC ZEND_FILE_LINE_ORIG_DC) ZEND_ATTRIBUTE_MALLOC; ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c:1884:19: error: ‘zval {aka struct _zval_struct}’ has no member named ‘type’ } else if(values->type == IS_STRING) { ^ /home/hamid/xhprof-0.9.2/extension/xhprof.c: At top level: /home/hamid/xhprof-0.9.2/extension/xhprof.c:789:10: warning: ‘hp_globals’ is static but used in inline function ‘hp_ignore_entry’ which is not static return hp_globals.ignored_function_names != NULL && ^ Makefile:193: recipe for target 'xhprof.lo' failed make: *** [xhprof.lo] Error 1 对我来说听起来非常不恰当。如果您期望该功能的主要结果是副作用,那么在使用def fn(): Either[Throwable, Unit]时似乎没有用处。这是因为它是monadic操作链的终端操作吗?

这些日子变得不那么受欢迎,也不那么惯用了,但我可能会选择Either来处理案件。另一个惯用的选择是,而不是在Try[A]中改变异常,以创建所有错误类型的密封特征层次结构,并从有效函数而不是原始Either实例返回那些。

我在REPL调用ThrowableRight()时没有看到您注意到的错误,您使用的是哪个版本的Right( () )