type-alias

Scala: abstracting over a path-dependent type in impilicit parameter

邮差的信 提交于 2019-12-22 15:39:42
问题 Let's say I have a class: abstract class NumericCombine[A:Numeric,B:Numeric]{ type AB <: AnyVal } I want to define a function that returns a value of type NumericCombine[A,B].AB . for instance: def plus[A: Numeric,B:Numeric](x: A, y: B): NumericCombine[A,B].AB but the compiler doesn't let me reference .AB in plus. FYI, this is the context of this question. I want to provide: implicit object IntFloat extends NumericCombine[Int,Float]{override type AB = Float} implicit object FloatInt extends

Scala type aliasing breaks the type compatibility

余生颓废 提交于 2019-12-22 06:21:34
问题 I always believed that type aliases always expand to their original type if necessary. But, here is a troublemaker def a[P](a: Option[P]) = { type Res = List[P] // result type alias Nil: Res // Replace this line with Nil: List[P] to clear the error } def b[V](v: V) = a(Some(v)): List[V] it fails with (scastie) error: type mismatch; found : Res (which expands to) List[P] required: List[V] You see that a converts Option[P] => List[P] and, since b supplies Some[V] , a converts Option[V] => List

Scala 2.11.5 compiler crash with type aliases and manifests

五迷三道 提交于 2019-12-20 02:59:13
问题 It appears that passing an alias to a wild-carded parameterized type to a function that tries to get an implicit Manifest for the type will crash the Scala 2.11.5 compiler. The following can be pasted in the 2.11.5 REPL to reproduce the crash: class C[T] def f[T](implicit m: Manifest[T]) = 0 type CAlias = C[_] val x = f[CAlias] The crash output is very verbose, but contains this info: scala.reflect.internal.FatalError: ?MethodType? while compiling: <console> during phase: globalPhase=erasure,

missing lifetime specifier [E0106] on type alias

我们两清 提交于 2019-12-19 07:51:10
问题 This code: use std::fmt; use std::result::Result::{self, Ok, Err}; #[derive(Clone)] #[derive(Copy)] enum Tile { White, Black, Empty } type Board = &[[Tile; 19]; 19]; Produces this error: Compiling go v0.1.0 (file:///home/max/gits/go_rusty) src/main.rs:12:14: 12:31 error: missing lifetime specifier [E0106] src/main.rs:12 type Board = &[[Tile; 19]; 19]; ^~~~~~~~~~~~~~~~~ error: aborting due to previous error Could not compile `go`. To learn more, run the command again with --verbose. I'm having

How to use a type alias to define a type constructor

烈酒焚心 提交于 2019-12-13 13:13:24
问题 Let's say I have some code that uses List def processList(input: List[Int]): List[Int] I want to replace list with other collection types, like Vector. Is there a way to define a type constructor so that I can write something like type SomeCollection[_] = List[_] def processList(input: SomeCollection[Int]): SomeCollection[Int] Now I have written processList in terms of SomeCollection. To change SomeCollection to Vector, I just change the type alias, and everywhere in the codebase where I use

Aliasing with Webpack 4 and awesome-typescript loader not working

久未见 提交于 2019-12-13 12:25:22
问题 I'm currently having issue getting aliasing to work properly. From my understanding, to get aliasing to work properly with webpack you have to: Versions "typescript": "2.8.3", "webpack": "4.16.2", "webpack-cli": "3.1.0", "awesome-typescript-loader": "5.2.0", "html-webpack-plugin": "3.2.0", "source-map-loader": "^0.2.3", define the alias in tsconfig as paths. I verified that my tsconfig and paths/aliasing is correct by building it. If it wasn't configured correctly, it would have failed the

Is it possible to create a template alias?

走远了吗. 提交于 2019-12-12 08:21:40
问题 Consider the following code: template< template< typename ... > class ... Ts > struct unite { template< typename ... T > struct type : Ts< T ... > ... { }; }; // This does not work as ::type does not name a type, but a template: // template< template< typename ... > class ... Ts > // using unite_t = typename unite< Ts ... >::type; template< typename > struct debug_none {}; template< typename > struct debug_cout {}; template< typename ... > struct raise_demangled {}; template< typename ... >

Swift 4: Non-nominal type 'T' does not support explicit initialization when converting Objective-c to Swift

放肆的年华 提交于 2019-12-11 07:10:04
问题 I'm trying to convert an Objective-C project to Swift, here is one of the .h file in Objective-C: typedef void(^PrintBlock)(HLPrinter *printer); @interface ShoppingViewController : UIViewController @property (copy, nonatomic) PrintBlock printBlock; @end and in the .m file, there is a function: HLPrinter *printer = [self getPrinter]; if (_printBlock) { _printBlock(printer); } And this is how I converted it into Swift: typealias PrintBlock = (_ printer: HLPrinter?) -> Void But when I tried to

Partial specializations of templatized alias declarations

岁酱吖の 提交于 2019-12-10 23:31:20
问题 In this question I am led to a particular solution which involves partial specializations of templatized alias declarations. The generic case is described in this answer. Suppose I have a template class template<typename T, ...> class X { // .... }; Rather than leaving T free and specializing the other template parameters I am in a situation in which the other arguments depend on T, and on T alone. As a very concrete example (more manageable than the example in the other question) consider a

How to define a function-local type alias of the function's type parameters (or their associated types)?

故事扮演 提交于 2019-12-10 18:43:25
问题 I have a generic function foo with some complex-ish trait bounds: use std::ops::Index; // This trait is just as an example trait Float { const PI: Self; fn from_f32(v: f32) -> Self; } // impl Float for f32, f64 ... fn foo<C>(container: &C) where C: Index<u32>, <C as Index<u32>>::Output: Float, { // ... } I now need to use the type <C as Index<u32>>::Output inside the function a bunch (e.g. to get π via ::PI or say ::from_f32(3.0) ). But this type is long to type out by hand and makes the