type-alias

Difference between an undefined abstract type member and an existential type

╄→гoц情女王★ 提交于 2020-07-10 05:18:49
问题 Given an uninitialised abstract type member is =:= equal to an existential type implicitly[Undefined =:= x forSome { type x }] // ok then why there seems to be a difference between them in object O { type Undefined implicitly[Undefined =:= _] // ok def g[F[_]](fun: F[_] => F[_]) = ??? def h[F[_]](fun: F[Undefined] => F[Undefined]) = ??? g[List](l => List(42)) // ok h[List](l => List(42)) // error } Note how g compiles whilst h raises type mismatch error. Furthermore consider object O { type

Difference between an undefined abstract type member and an existential type

末鹿安然 提交于 2020-07-10 05:17:13
问题 Given an uninitialised abstract type member is =:= equal to an existential type implicitly[Undefined =:= x forSome { type x }] // ok then why there seems to be a difference between them in object O { type Undefined implicitly[Undefined =:= _] // ok def g[F[_]](fun: F[_] => F[_]) = ??? def h[F[_]](fun: F[Undefined] => F[Undefined]) = ??? g[List](l => List(42)) // ok h[List](l => List(42)) // error } Note how g compiles whilst h raises type mismatch error. Furthermore consider object O { type

May I declare a member type alias to a type in a surrounding scope, using the same name?

江枫思渺然 提交于 2020-04-29 08:17:28
问题 I want a struct to contain a type alias to another type for metaprogramming purposes: struct Foo {}; struct WithNestedTypeAlias { using Foo = Foo; }; Then I can do stuff like WithNestedTypeAlias::Foo in a template etc. As I understand, this type alias is valid because it does not change the meaning of the Foo type. Clang compiles this happily. However, GCC complains: test-shadow-alias.cpp:4:20: error: declaration of ‘using Foo = struct Foo’ [-fpermissive] using Foo = Foo; ^ test-shadow-alias

Generic view controller won't work with delegate and extension

半世苍凉 提交于 2020-01-17 10:34:31
问题 I already posted a question but it was not clear about what I want. As @AlainT suggested, I filed a new one. I have a typealias tuple public typealias MyTuple<T> = (key: T, value: String) A protocol: public protocol VCADelegate: class { associatedtype T func didSelectData(_ selectedData: MyTuple<T>) } A view controller (VCA) with a table view class VCA<T>: UIViewController, UITableViewDelegate, UITableViewDataSource { var dataList = [MyTuple<T>]() weak var delegate: VCADelegate? // Error: can

Generic view controller won't work with delegate and extension

喜欢而已 提交于 2020-01-17 10:33:53
问题 I already posted a question but it was not clear about what I want. As @AlainT suggested, I filed a new one. I have a typealias tuple public typealias MyTuple<T> = (key: T, value: String) A protocol: public protocol VCADelegate: class { associatedtype T func didSelectData(_ selectedData: MyTuple<T>) } A view controller (VCA) with a table view class VCA<T>: UIViewController, UITableViewDelegate, UITableViewDataSource { var dataList = [MyTuple<T>]() weak var delegate: VCADelegate? // Error: can

Generic view controller won't work with delegate and extension

北城余情 提交于 2020-01-17 10:32:32
问题 I already posted a question but it was not clear about what I want. As @AlainT suggested, I filed a new one. I have a typealias tuple public typealias MyTuple<T> = (key: T, value: String) A protocol: public protocol VCADelegate: class { associatedtype T func didSelectData(_ selectedData: MyTuple<T>) } A view controller (VCA) with a table view class VCA<T>: UIViewController, UITableViewDelegate, UITableViewDataSource { var dataList = [MyTuple<T>]() weak var delegate: VCADelegate? // Error: can

Aliasing a template parameter pack

限于喜欢 提交于 2020-01-15 03:33:09
问题 Pre-Dramatic Hi, maybe this question is a duplicate, but I am relative new to template programming and actually I am not able to find a simple and short solution (-> only finding megabytes of " roxxor-template-magic " which I don't understand) matching my concrete and simple problem and so I feel a little bit lost now. Pre-Information I want to use a "type_container" as template parameter for a class. The container is a simple struct, which should also contain some typedefs for template

Does Rust have an idiomatic equivalent to F# typedefs?

℡╲_俬逩灬. 提交于 2020-01-01 04:37:49
问题 I'm re-writing existing code of mine in Rust 1.6 and I've found it very convenient in the source language to label a type by typedef. For example, in my card game I have a rank value in F# defined as: type Rank = uint8 回答1: From The Rust Programming Language section titled Creating Type Synonyms with Type Aliases: Rust provides the ability to declare a type alias to give an existing type another name. For this we use the type keyword. For example, we can create the alias Kilometers to i32

How to access a Java static method from Scala given a type alias for that class it resides in

ⅰ亾dé卋堺 提交于 2020-01-01 02:47:47
问题 Given the type-alias type Cal = java.util.Calendar how can the static getInstance method be accessed? I tried the following in Scala REPL: scala> type Cal = java.util.Calendar defined type alias Cal scala> Cal.getInstance <console>:8: error: not found: value Cal Cal.getInstance ^ scala> val Cal = java.util.Calendar <console>:7: error: object Calendar is not a value val Cal = java.util.Calendar ^ Is import java.util.{Calendar => Cal} followed by import Cal._ really my best bet? 回答1: You can't.

Describe recursive grammar with type aliases

*爱你&永不变心* 提交于 2019-12-24 02:37:07
问题 How can I describe this recursive grammar with type aliases: type FieldValue = Seq[String] :+: String :+: Int :+: Long :+: CNil type FieldLeaf = FieldValue :+: SubField :+: CNil type SubField = Seq[Field] type Field = (String, FieldLeaf) As it stands, the Scala compiler (2.12.1) gives me: Error:(14, 25) illegal cyclic reference involving type FieldLeaf type Field = (String, FieldLeaf) PS the context of this is parsing a recursive grammar with fastparse. Edit (in response to