小编fz_*_*lam的帖子

在参数类型而不是函数类型中放置约束有什么作用?

我在函数参数的类型中放置了一个约束,而不是在函数的类型中。
我认为这会导致语法错误或向函数类型添加更多信息。
但看起来约束被完全忽略了。

{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}

test :: a -> String
test (n :: (Num a, Ord a) => a) =
    if n > 10 then "Hello"
    else "World"

main = print "Hello World"
Run Code Online (Sandbox Code Playgroud)

这给出了以下类型错误:

Test3.hs:6:8: error:
    • No instance for (Num a) arising from a use of ‘n’
      Possible fix:
        add (Num a) to the context of
          the type signature for:
            test :: forall a. a -> String
    • In the first argument of …
Run Code Online (Sandbox Code Playgroud)

haskell

8
推荐指数
1
解决办法
166
查看次数

如何断言受歧视的联合在打字稿单元测试中具有某种变体?

我试图使用笑话在打字稿中编写单元测试。

// This is how foo() is defined:
// function foo(): 
//        {status: "OK"} | 
          {status: "ERROR", reason: "INVALID_ID"|"SOME_OTHER_ERROR"};

let res = foo();
expect(res.status).toEqual("ERROR");
expect(res.reason).toEqual("INVALID_ID");
// ^^^ this line gives error TS2339: Property 'reason' does not exist on type ....
Run Code Online (Sandbox Code Playgroud)

打字稿是否具有某种构造,assert(res.status == "ERROR")例如编译器可以在其中找出结果是这里的第二个变体?

如果没有,是否有其他单元测试框架在其expect()类似功能中向编译器提供必要的提示?

或者有更好的方法来返回错误foo()吗?

unit-testing typescript jestjs

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

在Java中调试 - 设置debugMode标志

为一个noobish问题道歉.

我正在开发一个JavaFX应用程序.

我想成立一​​个"全球性"的布尔类型变量"DebugMode",这样,当一个自定义的(我的意思是定制的,或采用自制)异常被抛出,的getMessage()函数可以检查DebugMode变量,看是否DebugMode是组.

如果DebugMode为'true',则异常可以给出调试的详细消息,或者只是为最终用户提供用户友好消息.

是否有可能在java中,就像PHP中的$ GLOBAL变量一样?或者有没有其他方法为开发人员和最终用户提供两种不同的异常消息?

java debugging javafx

4
推荐指数
1
解决办法
2921
查看次数

标签 统计

debugging ×1

haskell ×1

java ×1

javafx ×1

jestjs ×1

typescript ×1

unit-testing ×1