subtyping Questions

1

Solved

Why doesn't TypeScript complain when I assign a class to an interface, where the interface is a superset of the class. Example: interface AI { hello(msg: string | number): void; } class A { hell...
Grigson asked 9/3, 2022 at 23:7

0

How do I test for subtypes in both Python 2 and Python 3? In Python 2.7.18: >>> import typing >>> type_ = typing.List[str] >>> issubclass(type_, typing.List) True But in...
Portulaca asked 23/1, 2022 at 18:36

1

Solved

I'm coming from a Java background, and I'm trying to wrap my head around Haskell's type system. In the Java world, the Liskov Substitution Principle is one of the fundamental rules, and I'm trying ...
Protoxide asked 1/8, 2020 at 21:34

3

I wonder what is the reasoning behind the following behaviour? @ trait Bar defined trait Bar @ trait Foo { self: Bar => } defined trait Foo @ def x: Foo = ??? defined function x @ val y: Bar ...
Kabul asked 18/7, 2020 at 12:7

1

The following simple code: implicit val a: String = "abc" implicitly[a.type] fails to compile despite that a is totally in the scope and consistent in type: Error:(9, 13) could not fi...
Derisive asked 6/7, 2020 at 0:34

0

List of shapes infers to List[Shape] but list of boxed shapes infers to List[Box[Square | Circle]] scala> sealed trait Shape | case class Square() extends Shape | case class Circle() extends ...
Spring asked 31/5, 2020 at 18:40

2

Solved

Regarding the following C++ program: class Base { }; class Child : public Base { }; int main() { // Normal: using child as base is allowed Child *c = new Child(); Base *b = c; // Double po...
Solute asked 28/3, 2010 at 9:25

2

Solved

I'm reading java specs https://docs.oracle.com/javase/specs/jls/se10/html/jls-4.html#jls-4.10.2 and this line confuses me: D<U1 θ,...,Uk θ>, where D<U1,...,Uk> is a generic type whi...
Archdiocese asked 20/7, 2018 at 2:35

1

We often use type class dependence to emulate the sub typing relationship. e.g: when we want to express the sub typing relationship between Animal, Reptile and Aves in OOP: abstract class Animal...
Cornemuse asked 27/6, 2018 at 5:49

2

Solved

This question was originally posted by lookatme in the Perl6 IRC channel. The original intention is to constrain a Callable by using subsets or any other possible way. It works in signatures, howev...
Fustic asked 17/5, 2018 at 6:39

3

Here’s my thoughts on the question. Can anyone confirm, deny, or elaborate? I wrote: Scala doesn’t unify covariant List[A] with a GLB ⊤ assigned to List[Int], bcz afaics in subtyping “biunifica...

1

Solved

I have the following code: module Test : sig type +'a t val make : int -> [< `a | `b] t end = struct type 'a t = Foo of int | Bar of string let make = function | 0 -> (Foo 0 : [`a] ...
Flick asked 13/1, 2018 at 6:23

2

Solved

Given these types type a = [ `A ] type b = [ a | `B | `C ] and this function let pp: [< b] -> string = function | `A -> "A" | `B -> "B" | `C -> "C" applying a value of type ...
Belgian asked 9/11, 2017 at 21:45

2

I would like to have a A|B type to be the subtype of A|B|C. Is that possible to encode in Scala ? If yes, how ? I was hoping that I can make implicitly[¬¬[IF] <:< T] compile below (original ...
Baxy asked 22/7, 2017 at 13:46

1

Common sense suggests that subtyping should be covariant with respect to return type but contravariant with respect to argument types. So, the following should be rejected, because of the strictly ...
Endorsed asked 19/9, 2016 at 8:51

1

Solved

Why is this legal TypeScript? var x: number = 5 var y: Object = x Surely a number is not an Object. One might suspect that x is implicitly coerced (auto-boxed) to an object, but no: if (!(y ins...
Topsail asked 18/9, 2016 at 20:30

1

Solved

In his talk Compilers are Databases, Martin Odersky presents an interesting variance corner case: class Tree[-T] { def tpe: T @uncheckedVariance def withType(t: Type): Tree[Type] } T is define...
Foremost asked 11/4, 2016 at 20:52

1

I feel dumb for having browsed the marker section of the Rust documentation and the Wikipedia articles about subtyping and variance multiple times without it improving my understanding of the lifet...
Tungting asked 20/8, 2014 at 14:40

5

Solved

Consider the following pair of function definitions, which pass the type checker: a :: forall a. a a = undefined b :: Int b = a I.e. an expression of type forall a. a can be used where one of t...
Fabio asked 23/9, 2015 at 18:41

2

Solved

Assume class B inherits from class A. The following is legal Java: List<A> x; List<? super B> y = x; In terms of the specification, this means that List<A> assignsTo List<? ...
Fistic asked 24/4, 2015 at 20:39

3

The database I'm designing has an employees table; there can be multiple types of employees, one of which are medical employees. The database needs to also describe a many-to-many relation between ...
Cliffhanger asked 27/11, 2014 at 20:54

1

Suppose I've got a simple type class whose instances will give me a value of some type: trait GiveMeJustA[X] { def apply(): X } And I've got some instances: case class Foo(s: String) case class...
Bergmans asked 10/9, 2014 at 16:23

5

Solved

Based on the note at the end of this answer it looks like subtyping and inheritance are subtly different concepts in Java. What is it? Is inheritance only when a class declaration contains an exten...
Meredeth asked 28/8, 2014 at 15:35

2

Solved

wiki Contravariant_method_argument_type says overriding method has the subtyping rule as function type, but no language except one support contravariant argument type. I also not able to come up wi...
Vengeance asked 23/3, 2014 at 4:9

1

Solved

Below is the code I am trying to run: class Student { def printDetails = println("I am a student") def printSomeOtherDetails = println("I love Studying") } class ComputerScienceStudent extends ...
Kragh asked 6/11, 2013 at 20:11

© 2022 - 2024 — McMap. All rights reserved.