type-alias

In scala, how to make type class working for Aux pattern? - Part 2

随声附和 提交于 2021-02-19 03:46:28
问题 This is a follow up question of: In scala, how to make type class working for Aux pattern? Considering the following example: trait Base { type Out def v: Out } object Base { type Aux[T] = Base { type Out = T } type Lt[T] = Base { type Out <: T } class ForH() extends Base { final type Out = HNil override def v: Out = HNil } object ForH extends ForH } trait TypeClasses { class TypeClass[B] def summon[B](b: B)(implicit ev: TypeClass[B]): TypeClass[B] = ev } object T1 extends TypeClasses {

Abstract type member of a singleton object

家住魔仙堡 提交于 2021-02-08 08:31:51
问题 Abstract member method is illegal in a singleton object scala> object Foo { | def g: Int | } def g: Int ^ On line 2: error: only traits and abstract classes can have declared but undefined members as is abstract value member scala> object Foo { | val x: Int | } val x: Int ^ On line 2: error: only traits and abstract classes can have declared but undefined members however abstract type member is legal in a singleton object scala> object Foo { | type A | } object Foo so clearly the sense in

Abstract type member of a singleton object

半腔热情 提交于 2021-02-08 08:31:37
问题 Abstract member method is illegal in a singleton object scala> object Foo { | def g: Int | } def g: Int ^ On line 2: error: only traits and abstract classes can have declared but undefined members as is abstract value member scala> object Foo { | val x: Int | } val x: Int ^ On line 2: error: only traits and abstract classes can have declared but undefined members however abstract type member is legal in a singleton object scala> object Foo { | type A | } object Foo so clearly the sense in

TypeScript array of functions

廉价感情. 提交于 2021-01-27 04:08:26
问题 I was wondering how could one declare a typed-function array in TypeScript. For instance, say I have a field which can hold a function that has no arguments and returns void: private func: () => void; Now, say I wanted a field which can hold an array of such functions: private funcs: () => void []; This is obviously the wrong way to do what I intended since the compiler considers this to be a function which returns an array of voids. Trying to isolate the inline prototype declaration with

TypeScript array of functions

纵饮孤独 提交于 2021-01-27 04:07:08
问题 I was wondering how could one declare a typed-function array in TypeScript. For instance, say I have a field which can hold a function that has no arguments and returns void: private func: () => void; Now, say I wanted a field which can hold an array of such functions: private funcs: () => void []; This is obviously the wrong way to do what I intended since the compiler considers this to be a function which returns an array of voids. Trying to isolate the inline prototype declaration with

In scala, how to make type class working for Aux pattern?

非 Y 不嫁゛ 提交于 2021-01-25 07:18:09
问题 Here is a simple example: trait Base { type Out def v: Out } object Base { type Aux[T] = Base { type Out = T } class ForH() extends Base { type Out = HNil override def v: Out = HNil } object ForH extends ForH } class TypeClass[B] trait TypeClassLevel1 { def summon[B](b: B)(implicit ev: TypeClass[B]): TypeClass[B] = ev } object TypeClass extends TypeClassLevel1 { implicit def t1: TypeClass[Base.Aux[HNil]] = new TypeClass[Base.Aux[HNil]] implicit def t2: TypeClass[Int] = new TypeClass[Int] } it