inference

TypeScript type inference/narrowing challenge

你说的曾经没有我的故事 提交于 2019-12-01 17:16:53
问题 I'm currently trying to improve the types on some existing code. My code looks roughly like this: /* dispatcher.ts */ interface Message { messageType: string; } class Dispatcher<M extends Message> { on< MessageType extends M["messageType"], SubMessage extends M & { messageType: MessageType } >( messageType: MessageType, handler: (message: SubMessage) => void ): void { } } /* messages.ts */ interface AddCommentMessage { messageType: "ADD_COMMENT"; commentId: number; comment: string; userId:

understanding working of Drools guvnor

做~自己de王妃 提交于 2019-12-01 14:46:19
can any one plz let me know that how drool guvnor work i went to guvnor documentation but couldn't understand the core logic of how rules are processed and how we can use drools guvnor in coherence with java code Basically i want to know how java code interacts with drools guvnor api. There is very less documentation about latest drool 6. I suggest you watch this presentation by Mark Proctor on drools 6 (Drools Project Lead at Red Hat) and visit his Youtube Channel to watch screencasts of drools workbench and tutorials on building example applications. 来源: https://stackoverflow.com/questions

SPARQL Querying Transitive

依然范特西╮ 提交于 2019-12-01 03:29:46
I am a beginner to SPARQL and was wondering if there was a query which could help me return transitive relations. For example the n3 file below I would want a query that would return "a is the sameas c" or something along those lines. Thanks @prefix : <http://websitename.com/links/> . @prefix owl: <http://www.w3.org/2002/07/owl#> . :a owl:sameas :b. :b owl:sameas :c. You can use property paths if you are using a suitably enabled SPARQL 1.1 engine, you've tagged your question Jena so I assume you are using its ARQ engine which supports this feature. So you can write a query like the following:

Why doesn't C# do “simple” type inference on generics?

心已入冬 提交于 2019-11-29 22:36:51
问题 Just curious: sure, we all know that the general case of type inference for generics is undecidable. And so C# won't do any kind of sub-typing at all: if Foo<T> is generic, Foo<int> isn't a subtype of Foo<T> , or Foo<Object> or of anything else you might cook up. And sure, we all hack around this with ugly interface or abstract class definitions. But... if you can't beat the general problem, why not just limit the solution to cases that are easy. For example, in my list above, it is OBVIOUS

Capturing wildcards in Java generics

浪尽此生 提交于 2019-11-29 10:00:00
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 list input parameter ( i ) is seen as an Object : In this example, the compiler processes the i input

Calling template function without <>; type inference

会有一股神秘感。 提交于 2019-11-29 09:43:29
If I have a function template with typename T , where the compiler can set the type by itself, I do not have to write the type explicitly when I call the function like: template < typename T > T min( T v1, T v2 ) { return ( v1 < v2 ) ? v1: v2; } int i1 = 1, i2 = 2; int i3 = min( i1, i2 ); //no explicit <type> But if I have a function template with two different typenames like: template < typename TOut, typename TIn > TOut round( TIn v ) { return (TOut)( v + 0.5 ); } double d = 1.54; int i = round<int>(d); //explicit <int> Is it true that I always have to specify at least 1 typename? I assume

Grammar inference library?

余生长醉 提交于 2019-11-28 05:09:02
问题 What are the best (or any) open source libraries for regular or context-free grammar inference from a set of examples believed to be generated by a common grammar? I'd prefer a good library in Java, Python or Ruby, but of course beggars can't be choosers. I did some googling, but couldn't find any actual implementations, though I did find plenty of interesting references. This library looks interesting, but I couldn't find it available for download anywhere. Edit (2011-11-14): For clarity

Why not infer template parameter from constructor?

南楼画角 提交于 2019-11-26 11:43:45
my question today is pretty simple: why can't the compiler infer template parameters from class constructors, much as it can do from function parameters? For example, why couldn't the following code be valid: template<typename obj> class Variable { obj data; public: Variable(obj d) { data = d; } }; int main() { int num = 2; Variable var(num); //would be equivalent to Variable<int> var(num), return 0; //but actually a compile error } As I say, I understand that this isn't valid, so my question is why isn't it? Would allowing this create any major syntactic holes? Is there an instance where one

What is Hindley-Milner?

半世苍凉 提交于 2019-11-26 10:05:11
问题 I encountered this term Hindley-Milner , and I\'m not sure if grasp what it means. I\'ve read the following posts: Steve Yegge - Dynamic Languages Strike Back Steve Yegge - The Pinocchio Problem Daniel Spiewak - What is Hindley-Milner? (and why is it cool?) But there is no single entry for this term in wikipedia where usually offers me a concise explanation. Note - one has now been added What is it? What languages and tools implement or use it? Would you please offer a concise answer? 回答1:

Why not infer template parameter from constructor?

最后都变了- 提交于 2019-11-26 02:32:21
问题 my question today is pretty simple: why can\'t the compiler infer template parameters from class constructors, much as it can do from function parameters? For example, why couldn\'t the following code be valid: template<typename obj> class Variable { obj data; public: Variable(obj d) { data = d; } }; int main() { int num = 2; Variable var(num); //would be equivalent to Variable<int> var(num), return 0; //but actually a compile error } As I say, I understand that this isn\'t valid, so my