Publish to my blog (weekly)
-
코딩 코리아(Coding Korea): 스칼라의 TypeTag
- 위에 예제에서 볼수 있듯이 스칼라의 Manifest 는 Path dependent type 을 정확하게 확인할수 없는 결함을 갖고있다(스칼라에서 Path dependent type 은 같은 타입의 클라스라도 exact path 에 따라 instance 들이 틀리다고 명제되어있다. 그러므로 위의 경우에서도 둘다 Foo.Bar 이지만 path 가 틀리기 때문에 두 클라스의 Manifest 는 동일하지 않아야한다.)
- Manifest 처럼 TypeTag 의외도 ClassTypeTag 과 WeakTypeTag 이 있다. ClassTag 은 ClassManfiest 처럼 가장 위의 레벨에 있는 class type 만 생성한다.
- // ClassTag 은 Runtime 에서 오직 맨위에 레벨의 class type 만 제공하는것을 볼수있다
- // 그러므로 Full type information 이 필요하면 TypeTag 을 써야한다
- WeakTypeTag 은 주로 Macro 를 사용할때 같이 사용하게 된다.
- scala> def foo[T: TypeTag] = implicitly[TypeTag[T]]
- foo[Int]
- def bar[T] = foo[T]
- scala> def foo[T: WeakTypeTag] = implicitly[WeakTypeTag[T]]
- foo[Int]
- def bar[T] = foo[T]
-
-
-
Scala: Multiple type parameters for implicit class - Stack Overflow
- down vote accepted
Implicit classes don't work that way. They are a shorthand for implicit conversions. For instance
implicit class Foo(i: Int)
is equal toclass Foo(i: Int); implicit def Foo(i: Int) = new Foo(i)
-
-
- A class
-
- An object
- A package object
- SIP-13, Implicit Classes, “An implicit class must be defined in a scope where method definitions are allowed (not at the top level).”
- Putting Common Code in Package Objects,
- you can add new functionality to closed classes by writing implicit conversions and bringing them into scope when you need them.
- there’s no need to create a new class named
MyString
that extendsString
, and then useMyString
throughout your code instead ofString
; instead, you define the behavior you want, and then add that behavior to allString
objects in the current scope when you add theimport
statement. - how this works:
- The compiler sees a string literal
HAL
. - The compiler sees that you’re attempting to invoke a method named
increment
on theString
. - Because the compiler can’t find that method on the
String
class, it begins looking around for implicit conversion methods that are in scope that accept aString
argument. - This leads the compiler to the
StringImprovements
class, where it finds theincrement
method. - : String
- : String
- : String
-
-
Rust: A Scala Engineer's Perspective - BeachApe.
- Rust’s memory/ownership model is, to me, its main killer feature;
-
댓글