感谢@ 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) 使用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) 我是新手,并且一直在尝试练习某种类型级别的编程.我将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) 我已经开始使用我的无形解决方案来解决项目欧拉问题#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) 我一直致力于Okasaki的密集二进制数字系统的"无形样式"实现.它只是一个类型级别的位列表; 一种HList二进制Digit的.我已经完成了我的操作的初稿,其中包括您对自然数字所期望的标准数学运算.直到现在我才意识到编码中的一个大问题.如何在我的Induction示例中修复隐式分辨率?随意将整个代码段粘贴到REPL中.在这个例子中,对shapeless的唯一依赖是for DepFn1和DepFn2.
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) 如何重命名hdfs目录中的所有文件以获得.lzo扩展名?.lzo.index不应重命名文件.
例如,此目录列表:
Run Code Online (Sandbox Code Playgroud)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
这些文件是lzo压缩的,我需要它们才能让.lzohadoop识别扩展名.
是否可以在<sec:authorize />标签的access属性中使用通配符.
目前我有
<sec:authorize access="hasRole('TICKET_VIEW') or hasRole('TICKET_EDIT')">
但我希望能够使用
<sec:authorize access="hasRole('TICKET_*')">
这是可能的,还是有人知道一个可以完成同样事情的解决方案?
谢谢
是否存在转换函数的惯用方法
val x: A => (B, C) = ...
Run Code Online (Sandbox Code Playgroud)
至
val y: A => (C, B) = ...
Run Code Online (Sandbox Code Playgroud) scala ×5
shapeless ×4
bash ×1
combinators ×1
file-rename ×1
hadoop ×1
java ×1
jdbc ×1
macros ×1