subtype

Can we create subtypes for errors in Go?

不羁岁月 提交于 2019-12-13 02:51:02
问题 I want to create hierarchical errors in Go. Can we achieve this in Go ? For an example, I have following two errors. type Error1 struct { reason string cause error } func (error1 Error1) Error() string { if error1.cause == nil || error1.cause.Error() == "" { return fmt.Sprintf("[ERROR]: %s\n", error1.reason) } else { return fmt.Sprintf("[ERROR]: %s\nCaused By: %s\n", error1.reason, error1.cause) } } type Error2 struct { reason string cause error } func (error2 Error2) Error() string { if

JPA multiple discriminator values

梦想与她 提交于 2019-12-12 15:39:09
问题 We're setting up a new project and decided to use eclipselink for JPA. When creating our domain model we ran into a problem. We have a base class called organisation. We also have Supplier and Customer which both extend organisation. When JPA created the tables I saw that it uses a discriminator, the problem with this is that a supplier can also be a organisation. So what I basically want is (these are database tables to get the idea): A little example to help clarify this: We have a Customer

How do you instantiate a Map.Entry<K, V> array in Java? [duplicate]

余生颓废 提交于 2019-12-12 03:21:59
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Java Generics: Array containing generics I have a Java class which contains 2 methods which add and remove an element from an array. To make it generic it takes a subtype so it should be able to work on different types of objects. The problem is that when I instantiate it using MapEntry (where MapEntry is an implementation of java.util.Map.Entry) as the subtype. This results in a ClassCastException being thrown

Subtype constraints in interfaces

為{幸葍}努か 提交于 2019-12-11 13:19:21
问题 I want to compose several "traits" across several modules. A function might require multiple such "traits" as its input, i.e.: type 'a x_t = < get_x : int ; .. > as 'a constraint 'a = < get_b : float ; .. > val foo : x_t -> float composing these traits manually in the interface is cumbersome and error-prone, but perfectly possible. But in an ideal world, I should be able to use the "trait's" name instead of manually composing all the required fields, i.e. write something like: type 'a x_t = <

Existential types for F-Bounded Polymorphic types and non-generic subtypes?

大憨熊 提交于 2019-12-09 13:11:12
问题 I have two subtypes that I need to be F-bounded polymorphic by a type A , and a subtype of one of those subtypes, i.e. trait A[T <: A[T]] { def x: T } trait Ter extends A[Ter] trait For extends A[For] trait C extends Ter Next I try to implement a concrete type case class F2(l: List[A[_]]) extends For { def x: For = F2(l.map(_.x)) } But this fails to compile with: <console>:11: error: type mismatch; found : List[Any] required: List[A[_]] def x: For = F2(l.map(_.x)) ^ So, google says I need to

Relational data modeling for sub types

六月ゝ 毕业季﹏ 提交于 2019-12-09 07:06:59
问题 I am learning the Relational Model and data modeling. And I have some confusion in my mind regarding sub types. I know that data modeling is an iterative process and there are many different ways to model things. But I don't know how to choose between different options. Example Suppose we want to model the particles (molecule, atom, proton, neutron, electron, ...). Let's ignore Quark and other particles for simplicity. Since all particles of the same type behave the same, we are not going to

Defining subtype relation in Coq

情到浓时终转凉″ 提交于 2019-12-08 07:16:46
问题 Is there a way to define subtype relationship in Coq? I read about subset typing, in which a predicate is used to determine what goes into the subtype, but this is not what I am aiming for. I just want to define a theory in which there is a type (U) and another type (I), which is subtype of (U). 回答1: There is no true subtyping in Coq (except for universe subtyping, which is probably not what you want). The closest alternative is to use coercions, which are functions that the Coq type checker

Subtypes vs Derived Types in C++

随声附和 提交于 2019-12-08 03:54:53
问题 I recently heard one of my coworkers claim that the concept of a "subtype" is not defined in C++. He claims that "subtypes" are rightly called "derived types" in C++ terminology. Is this true? If I have: class A { }; class B : public A { }; Can I call B a subtype of A? Or is it only valid to call B a "derived type" of A in C++? 回答1: Subtype is not part of the common jargon in C++. The definition in Wikipedia (thanks Chad) is quite broad and in C++ could represent multiple different things,

Coq: Defining a subtype

蓝咒 提交于 2019-12-07 20:21:08
问题 I have a type, say Inductive Tt := a | b | c. What's the easiest and/or best way to define a subtype of it? Suppose I want the subtype to contain only constructors a and b . A way would be to parametrize on a two-element type, e.g. bool: Definition filt (x:bool): Tt := match x with | true => a | false => b end. Check filt true: Tt. This works but is very awkward if your expression has several (possibly interdependent) subtypes defined this way. Besides, it works only half way, as no subtype

MD5 in Oracle (DBMS_OBFUSCATION_TOOLKIT.MD5)

…衆ロ難τιáo~ 提交于 2019-12-07 09:14:46
问题 I'm trying to compose a function to obtain MD5 hashes from bits I've gathered here and there. I want to obtain the lower-case hexadecimal representation of the hash. I have this so far: CREATE OR REPLACE FUNCTION MD5 ( CADENA IN VARCHAR2 ) RETURN DBMS_OBFUSCATION_TOOLKIT.VARCHAR2_CHECKSUM AS BEGIN RETURN LOWER( RAWTOHEX( UTL_RAW.CAST_TO_RAW( DBMS_OBFUSCATION_TOOLKIT.MD5(INPUT_STRING => CADENA) ) ) ); END; I'm not sure about the return type of the function. DBMS_OBFUSCATION_TOOLKIT.VARCHAR2