All Questions
Tagged with polymorphism types
231
questions
-3
votes
1
answer
70
views
How do interfaces in Go work when implementing functions with parameters/return values of a generalised type? [closed]
I'm new to Go and a bit confused in how interfaces work when implemented, especially wrt. functions that have parameters. Say I have an interface with function foo that takes in an interface:
type I ...
0
votes
0
answers
61
views
How to specialize the return type of a method in Kotlin
I want to implement a specific persistence in Kotlin, where I need to wrap the object to be persisted; yet, I still want to access some part of the persisted (generic) object in a type-safe way. How ...
0
votes
1
answer
39
views
Subclassing a generic Kotlin class with type constraint
I'm running into problems combining subclassing polymorphism and generics (ad-hoc polymorphism) in Kotlin.
Here are my type definitions:
interface State
interface StatefulContainer<out S : State&...
1
vote
0
answers
25
views
Type narrowing not happening with generics [duplicate]
Using types to restrict the possible representation of data I have, the values I consider here can be of two kinds: Foo or Bar (aliases of string). As far as I can tell, it means that all values I ...
1
vote
0
answers
79
views
Dealing with assumed-type, assumed-rank dummy arguments
This question is a continuation of my previous post. One question per post, therefore asking a separate question. The accepted answer asserts
The compiler documentation's comments about the use of ...
0
votes
1
answer
146
views
implicit real - complex conversion in fortran
New standards of fortran are more strict about the mismatches between the calls and the procedure definition. However, there are a lot of legacy codes where, for instance, complex array is viewed as a ...
0
votes
0
answers
100
views
Storing any data type in container inside another container
I need to have a container inside other container that stores any type of data:
std::vector<std::vector<std::any>> vectors(5);
I need to use vector methods on any element of outer vector ...
2
votes
1
answer
59
views
Java type which accepts a class AND its interfaces (contravariance)
I have a class and an interface like this:
interface Employee {...}
class Developer implements Employee {...}
Then I have classes which implement steps in the onboarding process:
interface ...
0
votes
1
answer
130
views
How to determine the type of something in a derived class?
I'm making a farming simulator in which I have the base class Produce, which is inherited from by two classes Crops and Animals. Whenever time progresses I am looking to check through my array of ...
0
votes
2
answers
88
views
String manipulation macro: expected specifier-qualifier-list before ‘,’ token
I am trying to write a macro which will automate definition of polymorphic types achived by composition and function pointers.
I don't really know a lot about macro string manipulation. This is how I ...
2
votes
1
answer
94
views
Is it ok to say higer order functions (map, filter ...) achieve polymorphism?
map(array, f)
I thought higher order functions are polymorphic. Since that operates in many ways. But when I have searched about polymorphism, there was no such thing like 'anonymous functions or ...
3
votes
1
answer
372
views
How to correctly overload functions in TypeScript?
Can anyone please tell me what's the problem with types here? I'm trying to make myself clear with overloads in TS but that problem below makes me really confused...
type myNumbers = 1 | 2 | 3
type ...
0
votes
1
answer
60
views
class A with member B that has a constructor argument with a variable type
I'm looking to make class A a generic UI Inputbox, that holds a member B that gets a constructor argument with variable type. Class A should then be able to adapt the amount of input boxes depending ...
-2
votes
1
answer
97
views
Recover a nil interface through type assertion [duplicate]
Consider the following (demo https://go.dev/play/p/VrJx-eEij14)
type myError struct {
err error
}
func (e myError) Error() string { return e.err.Error() }
func main() {
var (
err ...
0
votes
1
answer
95
views
Is there a way to encode structural polymorphism in language nominal polymorphism type system?
Is there a way to encode structural polymorphism like type compatibility in TypeScript in language like C#?
Structural polymorphism is some thing like duck typing,
but limited to static type check, ...