polymorphism Questions
4
I'm new to Haskell and reading Haskell from first principles.
BTW this question is general not related to this book, I have taken following question as example
In Chapter 10, Section 10.5, Q 5, par...
Allman asked 28/4, 2021 at 20:52
3
Trying out polymorphism as a beginner. I think I am trying the same code in different languages, but the result is not the same :
C++
#include <iostream>
using namespace std;
class A {
pu...
Formulate asked 24/12, 2015 at 0:3
6
Solved
Languages like C#, Java has method overloads, which means if child class does not implement the method with exact signature will not overwrite the parent method.
How do we enforce the method signa...
Collinear asked 23/4, 2014 at 21:44
0
Given
trait Int // proper type
trait List[A] // 1st-order-kinded type constructor
trait Functor[F[_]] // higher-order-kinded type constructor taking type constructor
trait I[H[F[_]]] // higher-ord...
Yost asked 13/4, 2021 at 16:3
1
Solved
Is the extension GADT in Haskell destroying polymorphism, even in code that don't use GADTs ?
Here's a example which works and don't use GADT
{-# LANGUAGE RankNTypes #-}
--{-# LANGUAGE GADTs #-}
...
Appear asked 21/3, 2021 at 14:37
1
Solved
Type get generalized or not depending on the presence or absence of a binding.
This can lead to unexpected failure.
Is this a normal behavior, and is there a reason why ?
{-# LANGUAGE RankNTypes #-...
Siriasis asked 20/3, 2021 at 17:58
3
Solved
I'm trying to call a function on a polymorphic item. But I get the following error message at compile time:
'this' argument to member function 'select' has type 'const SelectParam', but function i...
Marcello asked 31/5, 2019 at 1:14
2
Solved
Out of sheer curiosity, I wonder if something like the following is possible in Haskell:
A function foo takes another function as an argument that is called in the body of foo more than once, chang...
Algernon asked 25/2, 2021 at 14:55
4
I've just started learning object oriented programming from the book head first java.It said that polymorphism enables me to create an array of the superclass type and then have all the subclasses ...
Raymundorayna asked 19/1, 2019 at 12:0
6
Using a spin on the zoo example:
public class ZooPen {
public String type;
public List<Animal> animals;
}
public class Animal {
public String name;
public int age;
}
public class Bird e...
Salpingectomy asked 10/5, 2013 at 18:50
2
I'm looking for guidance around a pattern I frequently encounter in my PostgreSQL table design. I want to know if I'm thinking about this wrong or if maybe this is a Relational DB limit.
I have a t...
Guesthouse asked 9/2, 2021 at 19:57
5
Solved
Using the sizeof operator, I can determine the size of any type – but how can I dynamically determine the size of a polymorphic class at runtime?
For example, I have a pointer to an Animal, and I...
Engender asked 11/9, 2009 at 15:59
1
Solved
I have this simple generic function:
fn add_five<T: Into<i32>>(t: T) -> i32 {
5_i32 + t.into()
}
Which I would like to express using the From trait instead of the Into trait, howev...
Placeman asked 6/2, 2021 at 21:55
2
Solved
I have a trait in Rust that offers a few default implementations for its functions.
trait MyTrait {
fn do_something(&self);
fn say_hello(&self) {
println!("Hello I am default")...
Outgrow asked 6/2, 2021 at 13:2
2
Solved
AsRef documentation writes
Used to do a cheap reference-to-reference conversion.
I understand reference-to-reference part what does it mean by cheap? I hope it has nothing to do with complexity t...
Contraction asked 3/2, 2021 at 11:11
1
Solved
I want to write a function that reads the contents of a file, and raises an error if it fails. I want to call this function from a python script, so I'm including some mentions of Python below in c...
Weatherspoon asked 22/1, 2021 at 12:49
4
Solved
I have been studying Inheritance in Java and the writer makes the statement "it is the type of object being referred to (not the type of reference variable) that determines which version of an over...
Magenmagena asked 18/11, 2017 at 2:50
4
Solved
Motivation
The C++ Core Guidelines recommends using dynamic_cast when "class hierarchy navigation is unavoidable." This triggers clang-tidy to throw the following error: Do not use static...
Menard asked 21/8, 2020 at 9:32
2
Solved
Consider the following code where the Writer_I acts as an interface. Other classes which fulfil the contract of writing element types in correct form can derive from it. Here, printf and streams ar...
Hurley asked 8/1, 2021 at 11:29
6
Solved
Suppose I have the following class:
public class FixExpr {
Expr<FixExpr> in;
}
Now I want to introduce a generic argument, abstracting over the use of Expr:
public class Fix<F> {
...
Prostitution asked 18/5, 2009 at 9:50
2
Solved
What are the exact semantics of equality constraints? Are these two types exactly equivalent?
f :: Int -> IO [T]
g :: (a ~ T) => Int -> IO [a]
Is g a monomorphic or a polymorphic function...
Gossamer asked 1/1, 2021 at 16:53
4
I am new to cleaning code/refactoring and I learned to avoid having long switch statements like the one I have below. I discovered that polymorphism is a helpful technique to shorten complex switch...
Pathology asked 17/12, 2020 at 17:7
2
I have a simple class hierarchy that I want to serialize using System.Text.Json.
There are 3 classes. The base is Shape. Inherited ones are Box and Circle.
I have a plan to use these classes as ...
Tarrel asked 3/10, 2019 at 18:40
10
Solved
What is the difference between the Strategy pattern and Polymorphism in Java?
I'm confused that whatever is achieved via Strategy Pattern is basically possible by polymorphism. Correct me if I'm w...
Perspective asked 24/7, 2015 at 11:2
4
Solved
I have code that is somewhere between c++17 and c++20. Specifically, we have c++20 enabled on GCC-9 and clang-9, where it is only partially implemented.
In code we have quite big hierarchy of polym...
Heck asked 26/10, 2020 at 21:3
© 2022 - 2024 — McMap. All rights reserved.