inference

Java how to infer type from data coming from multiple sources

陌路散爱 提交于 2020-01-16 06:55:06
问题 I'm developing a java server that collects data from multiple sensors. These sensors usually return the queried values as string values. In the header it's indicated the data type that the server has to use to cast the received value. These value can be integer, boolean, double, float, and long. It might happen that the sensors don't provide the "data type description" of the values so: I want to find a way to understand the data type it analyzing the received string. I was thinking about

scala macros: defer type inference

廉价感情. 提交于 2020-01-14 10:16:11
问题 Preamble: this is based on @Travis Brown's macro based solution to copying case class properties. Given: trait Entity[E <: Entity[E]]{self:E=> def id: Int def withId(id: Int) = MacroCopy.withId(self,id) } case class User(id: Int, name: String) extends Entity[User] and the Macro implementation: object MacroCopy { import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context def withId[T](entity: T, id: Int): T = macro withIdImpl[T] def withIdImpl[T: c.WeakTypeTag] (c:

scala macros: defer type inference

徘徊边缘 提交于 2020-01-14 10:15:28
问题 Preamble: this is based on @Travis Brown's macro based solution to copying case class properties. Given: trait Entity[E <: Entity[E]]{self:E=> def id: Int def withId(id: Int) = MacroCopy.withId(self,id) } case class User(id: Int, name: String) extends Entity[User] and the Macro implementation: object MacroCopy { import scala.language.experimental.macros import scala.reflect.macros.blackbox.Context def withId[T](entity: T, id: Int): T = macro withIdImpl[T] def withIdImpl[T: c.WeakTypeTag] (c:

Capturing wildcards in Java generics

╄→尐↘猪︶ㄣ 提交于 2020-01-10 03:52:09
问题 From this Oracle Java tutorial: The WildcardError example produces a capture error when compiled: public class WildcardError { void foo(List<?> i) { i.set(0, i.get(0)); } } After this error demonstration, they fix the problem by using a helper method: public class WildcardFixed { void foo(List<?> i) { fooHelper(i); } // Helper method created so that the wildcard can be captured // through type inference. private <T> void fooHelper(List<T> l) { l.set(0, l.get(0)); } } First, they say that the

generic adder “inference architecture”: simulation error

情到浓时终转凉″ 提交于 2020-01-07 01:21:11
问题 So, I have to create a generic N-bit adder with carry in and carry out. I have made two fully working architectures so far, one using the generate function and one using the rtl description as follows: entity: library ieee; use ieee.std_logic_1164.all; use ieee.numeric_std.all; entity adder_n is generic (N: integer:=8); port ( a,b: in std_logic_vector(0 to N-1); cin: in std_logic; s: out std_logic_vector(0 to N-1); cout: out std_logic); end adder_n; architectures 1 and 2: --STRUCT

Inference in protége

大憨熊 提交于 2020-01-06 17:58:36
问题 I'm building an ontology to find peoples' skills. I want to infer that when a person A passed a course B and course B provides skill C, then person A has skill C. Is there a way to do this in Protégé? 回答1: Sure, you're saying that when you have: A &rightarrow; passed B &rightarrow; providesSkill C you want to infer that A &rightarrow; hasSkill C You can do that with the subproperty chain axiom: passed &bullet; providesSkill &sqsubseteq; hasSkill For a more detailed example of how to add these

Typescript infer function parameters in derived class

≡放荡痞女 提交于 2020-01-04 12:42:49
问题 I noticed that when implementing a generic interface (or class) and explicitly stating the types of those generics, the parameter types for functions inside the subclass are not inferred. interface MyInterface<T> { open(data: T): void } class MyClass implements MyInterface<string> { open(data) { // Data should be string, but is any } } The current correct way to do this would be the following: open(data: string) { ... } However, this forces me to enter the type multiple times which seems

Why can't these generic type parameters be inferred?

只谈情不闲聊 提交于 2020-01-02 05:34:49
问题 Given the following interfaces/classes: public interface IRequest<TResponse> { } public interface IHandler<TRequest, TResponse> where TRequest : IRequest<TResponse> { TResponse Handle(TRequest request); } public class HandlingService { public TResponse Handle<TRequest, TResponse>(TRequest request) where TRequest : IRequest<TResponse> { var handler = container.GetInstance<IHandler<TRequest, TResponse>>(); return handler.Handle(request); } } public class CustomerResponse { public Customer

Jena: How to infer data / performance issues

喜欢而已 提交于 2020-01-02 03:40:05
问题 I'd like to use Jena's inference capabilities, but I'm having some performance problems when I am using InfModel. Here's a simplified overview of my ontology: Properties: hasX (Ranges(intersection): X, inverse properties: isXOf) |-- hasSpecialX (Ranges(intersection): X, inverse properties: isSpecialXOf) isXOf (Domains(intersection): X, inverse properties: hasX) |--isSpecialXOf (Domains(intersection): X, inverse properties: hasSpecialX) Furthermore there's a class 'Object': Object hasSpecialX

Type intersections using any

与世无争的帅哥 提交于 2019-12-29 08:15:10
问题 From https://github.com/Microsoft/TypeScript/pull/3622: Supertype collapsing: A & B is equivalent to A if B is a supertype of A. However: type a = string & any; // Resolves to any, not string!? This intersection resolves to any. Isn't 'any' a supertype of string? So shouldn't this intersection be just string, due to supertype collapsing? What am I missing? The use case here is something like: type PropertyMap = { prop1: { name: "somename"; required: any; }; prop2: { name: "someothername";