polymorphic-functions

    0热度

    1回答

    我试图在函子上使用std::result_of。为什么我会得到这些结果? #include <typeinfo> struct my_logical_not { template<typename A> bool operator()(const A &value) const { return !value; } }; struct my_pa

    1热度

    2回答

    假设我需要不同的输出,具体取决于函数的多态参数的类型。我的初始尝试失败一些神秘的错误消息: choice :: a -> Int choice (_ :: Int) = 0 choice (_ :: String) = 1 choice _ = 2 然而,我们可以通过在不同的数据构造包裹所需类型固定,很容易并使用这些中的模式匹配: data Choice a = IntChoice In

    1热度

    2回答

    我没有看到这个bug在此实现: CREATE FUNCTION foo(anyelement) RETURNS SETOF int AS $f$ SELECT id FROM unnest(array[1,2,3]) t(id) WHERE CASE WHEN (pg_typeof($1)::text)='integer' THEN $1::int>2 ELSE true EN

    0热度

    2回答

    我正试图在postgresql中实现访问函数'isnull'这个函数将一个表达式作为参数,如果null已经传递,函数返回true;如果它不为null,则返回false。我知道postgres有'IS NULL'和'NOT NULL'关键字在我将字符串或空值本身传递给函数时,我不断收到多态错误,因为它们都是未知类型。 该方法必须使用函数完成。 我到目前为止有: CREATE OR REPLACE F

    0热度

    2回答

    我有这样的多态函数: def findFirst[A](as: Array[A], p: A => Boolean): Int = { @annotation.tailrec def loop(n: Int): Int = { if(n >= as.length) -1 else if(p(as(n))) n else loop(n + 1)