小编bee*_*alo的帖子

实现具有One Inhabitant的类型的值

感谢@ MilesSabin的回答,我可以编写一个类型级的Fibonacci序列:

sealed trait Digit
case object Zero extends Digit
case object One extends Digit

sealed trait Dense { type N <: Dense }
sealed trait DNil extends Dense { type N = DNil }
case object DNil extends DNil
final case class ::[+H <: Digit, +T <: Dense](digit: H, tail: T) extends Dense {
  type N = digit.type :: tail.N
}

/* The `A`th Fibonacci number is `B` */
trait Fib[A <: Dense, B <: Dense]

object …
Run Code Online (Sandbox Code Playgroud)

macros scala type-level-computation shapeless

21
推荐指数
0
解决办法
457
查看次数

为什么这段代码不关闭JDBC连接?(Java 7 Autocloseable意外行为)

使用Java 7u5和try-with-resources构造,以下代码似乎泄漏了jdbc连接:

try (Connection connection = ..; PreparedStatement stmt = ..) {
    stmt.setString(..);
    return stmt.executeUpdate() > 0;
}
Run Code Online (Sandbox Code Playgroud)

下一段代码按预期和预期工作:

int ret = 0;

try (Connection connection = ..; PreparedStatement stmt = ..) {
    stmt.setString(..);
    ret = stmt.executeUpdate();
}

return ret > 0;
Run Code Online (Sandbox Code Playgroud)

似乎在第一种情况下,该Connection.close()方法未被调用.

我正在使用最新的mysql连接器.这是出乎意料的行为,对吗?

测试

以下测试不会打印CLOSED:

public class Test implements AutoCloseable {

public static void main(String[] args) throws Exception {
    System.out.println(doTest());
}

private static boolean doTest() throws Exception {
    try (Test test …
Run Code Online (Sandbox Code Playgroud)

java jdbc connection-leaks try-with-resources

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

Project Euler#1的Scala无形代码

我是新手,并且一直在尝试练习某种类型级别的编程.我将Project Euler的问题#1作为我的第一个挑战.

我开始编写常规的scala代码:

object ProjectEuler1 {
  def e1(limit: Int) = (1 until limit).foldLeft(0) {
    case (acc, x) if x % 3 * x % 5 == 0 => acc + x
    case (acc, _)                       => acc
  }
  val out = e1(10)
  assert(out == 23)
}
Run Code Online (Sandbox Code Playgroud)

然后,我想出了这个工作无形的实现poly:

object ProjectEuler1Shapeless extends App {
  import shapeless._
  import nat._
  import ops.nat._
  import poly._
  import test.typed

  trait eLP extends Poly1 {
    implicit def default[A <: Nat] = at[A] { _ => …
Run Code Online (Sandbox Code Playgroud)

scala type-level-computation shapeless

11
推荐指数
1
解决办法
621
查看次数

项目欧拉的Scala无形代码#2

我已经开始使用我的无形解决方案来解决项目欧拉问题#2.

我可以Nth用这段代码将所有偶数纤维加在一起,直到偶数:

import shapeless._, nat._, ops.nat.Sum

trait Fibonacci[N <: Nat] { type Out <: Nat }

object Fibonacci {
  type Aux[N <: Nat, Out0 <: Nat] = Fibonacci[N] { type Out = Out0 }

  def apply[N <: Nat](i: Nat)(implicit fib: Aux[i.N, N], n: Witness.Aux[N]):N = n.value

  implicit val fib0 = new Fibonacci[_0] { type Out = _2 }
  implicit val fib1 = new Fibonacci[_1] { type Out = _3 }

  implicit def fibN[I <: Nat, L …
Run Code Online (Sandbox Code Playgroud)

scala type-level-computation shapeless

7
推荐指数
1
解决办法
360
查看次数

隐式解决失败?

我一直致力于Okasaki的密集二进制数字系统的"无形样式"实现.它只是一个类型级别的位列表; 一种HList二进制Digit的.我已经完成了我的操作的初稿,其中包括您对自然数字所期望的标准数学运算.直到现在我才意识到编码中的一个大问题.如何在我的Induction示例中修复隐式分辨率?随意将整个代码段粘贴到REPL中.在这个例子中,对shapeless的唯一依赖是for DepFn1DepFn2.

import shapeless.{ DepFn1, DepFn2 }

sealed trait Digit
case object Zero extends Digit
case object One extends Digit

sealed trait Dense { type N <: Dense }

final case class ::[+H <: Digit, +T <: Dense](digit: H, tail: T) extends Dense {
  type N = digit.type :: tail.N
}

sealed trait DNil extends Dense {
  type N = DNil
}

case object DNil extends DNil

/* …
Run Code Online (Sandbox Code Playgroud)

scala type-level-computation shapeless

7
推荐指数
1
解决办法
399
查看次数

在hadoop中批量重命名

如何重命名hdfs目录中的所有文件以获得.lzo扩展名?.lzo.index不应重命名文件.

例如,此目录列表:

file0.lzo file0.lzo.index file0.lzo_copy_1 
Run Code Online (Sandbox Code Playgroud)

可以重命名为:

file0.lzo file0.lzo.index file0.lzo_copy_1.lzo 
Run Code Online (Sandbox Code Playgroud)

这些文件是lzo压缩的,我需要它们才能让.lzohadoop识别扩展名.

bash hadoop file-rename

6
推荐指数
2
解决办法
9776
查看次数

Spring Security使用通配符授权访问角色

是否可以在<sec:authorize />标签的access属性中使用通配符.

目前我有 <sec:authorize access="hasRole('TICKET_VIEW') or hasRole('TICKET_EDIT')">

但我希望能够使用 <sec:authorize access="hasRole('TICKET_*')">

这是可能的,还是有人知道一个可以完成同样事情的解决方案?

谢谢

spring-security

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

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