Publish to my blog (weekly)

    • 일반적으로, 표현식의 평가되지 않는 형태를 성크(thunk)라고 부릅니다.
    • 평가되지 않은 채로 전달 할 인수에는 그 형식 바로 앞에 화살표 => 만 붙입니다. 함수의 본문에서는 =>로 지정된 인수를 평가하는 데 어떤 특별한 구문이 필요하지 않습니다.
    • 그냥 평소대로 해당 식별자를 참조하면 됩니다
    • 이 함수를 호출하는 데에도 특별한 구문이 필요하지 않습니다. 그냥 보통의 함수 호출 구문을 사용하면 스칼라가 성크 안의 표현식을 알아서 감싸줍니다
    • 평가되지 않은 채로 함수에 전달되는 인수는 함수의 본문에서 참조된 장소마다 한 번씩 평가됩니다. 즉, 스칼라는 인수 평가의 결과를 캐싱하지 않습니다.
    • This scenario is sometimes called "two-legged OAuth," or "2LO."
    • The related term "three-legged OAuth" refers to scenarios in which your application calls Google APIs on behalf of end users, and in which user consent is sometimes required.
    • Other
      • 이 방법을 사용하자...
      • 펑터는 Functor 타입클래스를 구현하는 데이터 타입이다.
      •  
      • 어플리커티브는 Applicative 타입클래스를 구현하는 데이터 타입이다.
      •  
      • 모나드는 Monad 타입클래스를 구현하는 데이터 타입이다.
      •  
      • Maybe는 이 세가지를 모두 구현한다. 따라서 펑터이고, 어플리커티브이며, 모나드이다.
      • 펑터:  fmap이나 <$>를 사용하여 함수를 포장된 값에 적용한다.
      •  
      •   어플리커티브: <*>나 liftA를 사용하여 포장된 함수를 포장된 값에 적용한다.
      •  
      •   모나드: >>=나 liftM을 사용하여 포장된 값을 리턴하는 함수를 포장된 값에 적용한다.
    • 임의의 값을 특정 함수를 통해 변경하는 것을 말합니다. 변경된 값은 같은 타입일 수도 있고 다른타입일 수도 있습니다. 즉 map이 가능하다면 functor라고 말할 수 있습니다.
    • 함수를 통해 type을 바꿀 있다면 (mappable) functor 라고 부를수 있습니다.
    • covariant)
      • 일반적인 Java, C++에서의 상속관계로 이해할 수 있다.
    • 반공변성(contravariant)
    • invariant)
    • 이란 한 마디로 함수를 파라미터로 전달 받거나, 함수를 리턴하는 함수를 말합니다.
    • 이 조건이 성립하기 위해서는 기본적으로 함수가 FirstClassCitizen이여야 합니다.
    • 함수를 인자로 받거나 함수를 반환하는 함수입니다
      • 아래 3 가지조건을 충족한다면 1급 객체라고 할수 있습니다.

        1. 변수나 데이타에 할당 할 수 있어야 한다.
        2. 객체의 인자로 넘길 수 있어야 한다.
        3. 객체의 리턴값으로 리턴 할수 있어야 한다.
    • a -> String 함수 타입 왼쪽에 Show a =>라는 컨텍스트(context)가 추가되어 있는 것을 볼 수 있습니다. 여기서 => 앞에 나오는 Show aa라는 타입이 Show라는 타입 클래스를 구현한 타입이어야 한다는 뜻입니다
    • 위 정의의 의미는 타입 aShow라는 타입 클래스의 인스턴스가 되기 위해서는a -> String이라는 타입을 가진 show 함수를 제공해야 한다는 뜻입니다. 여기서 Show타입 클래스는 Show 타입 클래스를 구현하는 타입들이 갖춰야 하는 일종의 인터페이스라고 이해할 수 있습니다.
    • 이처럼 show라는 함수는 실제로는 각 타입별로 구현이 다르지만, 우리는 타입별로 구분할 필요 없이 show라는 하나의 심볼만 사용하면 하스켈이 알아서 인자 타입에 맞는 실제show 함수 구현을 찾아서 불러주는 것입니다.
    • 하나의 심볼을 타입에 따라 서로 다른 의미로 사용하는 방법을오버로딩이라고 부르고, 하스켈의 타입 클래스는 오버로딩을 구현하기 위한 방법입니다.
    • Mergeable a라는 컨텍스트
    • First, let’s define a trait.
    • Type classes always take one or more type parameters, and they are usually designed to be stateless, i.e. the methods defined on our NumberLike trait operate only on the passed in arguments.
    • The second step in implementing a type class is usually to provide some default implementations of your type class trait in its companion object.
    • implicit
    • implicit
    • As you can see, members of type classes are usually singleton objects. Also, please note the implicit keyword before each of the type class implementations. This is one of the crucial elements for making type classes possible in Scala, making type class members implicitly available under certain conditions.
    • import Math.NumberLike
    • (implicit ev: NumberLike[T])
    • intimidating
      • 친밀한 것...
    • his is the case if an implicit value has been declared and made available in the current scope
    • If and only if no other implicit value can be found, the compiler will look in the companion object of the type of the implicit parameter.
    • putting your default type class implementations in the companion object of your type class trait means that users of your library can easily override these implementations with their own ones, which is exactly what you want.
    • Users can also pass in an explicit value for an implicit parameter to override the implicit values that are in scope.
    • @implicitNotFound("No member of type class NumberLike in scope for ${T}")
    • As a shortcut for implicit parameters with only one type parameter, Scala provides so-called context bounds.
    • verbose
      • 장황한
    • (implicit ev: NumberLike[T])
    • [T : NumberLike]
    • [T: NumberLike]
    • implicitly[NumberLike[T]]
    • A context bound T : NumberLike means that an implicit value of type NumberLike[T] must be available, and so is really equivalent to having a second implicit parameter list with a NumberLike[T] in it.
    • If you want to access that implicitly available value, however, you need to call the implicitly method, as we do in the iqr method.
    • If your type class requires more than one type parameter, you cannot use the context bound syntax.
    • import Math.NumberLike  import org.joda.time.Duration
    • implicit
    • import
    • mean(durations).getStandardHour
    • Statistics._
    • import JodaImplicits._
    • Numeric
    • Ordering
    • object serialization and deserialization,
    • Mapping between Scala types and ones supported by your database driver is also commonly made customizable and extensible via type classes.
    • stumble upon
      • …를 우연히 만나다(=meet by chance).
    • inevitably
      • 필연적으로, 아니다 다를까시피
    • retroactive
      • 소급하는,If a decision or action is retroactive, it is intended to take effect from a date in the past.
    • You will see that this technique is especially useful when writing libraries intended to be used by others,
    • type classes also have their use in application code to decrease coupling between modules.
    • Here our instance object looks like we’re calling a method.
    • Here is a trivial example that only serves to remove the need to use ‘new’ to create an instance.
    • This trait defines the apply() syntactic sugar we learned earlier, allowing you to call an object like you would a function.
    • a function that takes one argument is an instance of a Function1 trait.
    • There is Function0 through 22.
    • You can pass classes around and use them as functions and functions are just instances of classes under the covers.
    • The syntactic sugar of apply helps unify the duality of object and functional programming.
    • No, methods in classes are methods. Methods defined standalone in the repl are Function* instances.
    • Weak hash maps are useful for tasks such as caching, where you want to re-use an expensive function's result if the function is called again on the same key.
    • If keys and function results are stored in a regular hash map, the map could grow without bounds, and no key would ever become garbage.
    • Using a weak hash map avoids this problem. As soon as a key object becomes unreachable, it's entry is removed from the weak hashmap

Posted from Diigo. The rest of my favorite links are here.

댓글

이 블로그의 인기 게시물

Publish to my blog (weekly)

Publish to my blog (weekly)