Search Results

Search found 99 results on 4 pages for 'inference'.

Page 1/4 | 1 2 3 4  | Next Page >

  • Describe the Damas-Milner type inference in a way that a CS101 student can understand

    - by user128807
    Hindley-Milner is a type system that is the basis of the type systems of many well known functional programming languages. Damas-Milner is an algorithm that infers (deduces?) types in a Hindley-Milner type system. Wikipedia gives a description of the algorithm which, as far as I can tell, amounts to a single word: "unification." Is that all there is to it? If so, that means that the interesting part is the type system itself not the type inference system. If Damas-Milner is more than unification, I would like a description of Damas-Milner that includes a simple example and, ideally, some code. Also, this algorithm is often said to do type inference. Is it really an inference system? I thought it was only deducing the types. Related questions: What is Hindley Miller? Type inference to unification problem

    Read the article

  • make inference rule for files in a folder

    - by Gauthier
    I use GNU make, I want my source files and object files to be in different folders. As a first step, I want the source files at the root of my project folder, and the object files in a subfolder (say Debug/). The inference rule would be: .ss.obj: echo Assembling $*.ss... $(ASSEMBLY) $(2210_ASSEMBLY_FLAGS) $*.ss -o Debug\$*.obj but in that case, make rebuilds all files all the time, since there are no .obj in the root folder. Is there a way to include a folder for the target in the line .ss.obj? I also tried: $(OBJS_WITH_PATH):$(SRC) echo Assembling $<... $(ASSEMBLY) $(ASSEMBLY_FLAGS) $< -o $@ with $(SRC) as a list of all my sources, $(OBJS_WITH_PATH) built that way: OBJS_WITH_PATH = $(patsubst %.ss,Debug\\%.obj,$(SRC)) but that builds a dependency on all source files for all object files. What I would like is to modify the inference rule I wrote first, to take Debug/*.obj files. What it says now is no rule to make target Debug/asdfasdf.obj.

    Read the article

  • Inference engine to calculate matching set according to internal rules

    - by Zecrates
    I have a set of objects with attributes and a bunch of rules that, when applied to the set of objects, provides a subset of those objects. To make this easier to understand I'll provide a concrete example. My objects are persons and each has three attributes: country of origin, gender and age group (all attributes are discrete). I have a bunch of rules, like "all males from the US", which correspond with subsets of this larger set of objects. I'm looking for either an existing Java "inference engine" or something similar, which will be able to map from the rules to a subset of persons, or advice on how to go about creating my own. I have read up on rule engines, but that term seems to be exclusively used for expert systems that externalize the business rules, and usually doesn't include any advanced form of inferencing. Here are some examples of the more complex scenarios I have to deal with: I need the conjunction of rules. So when presented with both "include all males" and "exclude all US persons in the 10 - 20 age group," I'm only interested in the males outside of the US, and the males within the US that are outside the 10 - 20 age group. Rules may have different priorities (explicitly defined). So a rule saying "exclude all males" will override a rule saying "include all US males." Rules may be conflicting. So I could have both an "include all males" and an "exclude all males" in which case the priorities will have to settle the issue. Rules are symmetric. So "include all males" is equivalent to "exclude all females." Rules (or rather subsets) may have meta rules (explicitly defined) associated with them. These meta rules will have to be applied in any case that the original rule is applied, or if the subset is reached via inferencing. So if a meta rule of "exclude the US" is attached to the rule "include all males", and I provide the engine with the rule "exclude all females," it should be able to inference that the "exclude all females" subset is equivalent to the "include all males" subset and as such apply the "exclude the US" rule additionally. I can in all likelihood live without item 5, but I do need all the other properties mentioned. Both my rules and objects are stored in a database and may be updated at any stage, so I'd need to instantiate the 'inference engine' when needed and destroy it afterward.

    Read the article

  • Retail knowledge inference

    - by blueomega
    So i am doing a research on how can i infer knowledge from reports (not with a specific format), but after pre processing, i should have some kind of formatted data. A fairly basic inference would be: "Retailer has X stock." and "X is sellable." - "Retailer sells X" the knowledge i focus is retail domain oriented, and if possible i should improve its efficiency with each iteration. Is this scifi(some of my friends think it is)? The related stuff i find online are "expert systems" that find anomalies, fuzzy inference systems and some rants about "easy knowledge". Can you help me with some points for me to focus or orient me in some research directions? blueomega

    Read the article

  • Explain ML type inference to a C++ programmer

    - by Tsubasa Gomamoto
    How does ML perform the type inference in the following function definition: let add a b = a + b Is it like C++ templates where no type-checking is performed until the point of template instantiation after which if the type supports the necessary operations, the function works or else a compilation error is thrown ? i.e. for example, the following function template template <typename NumType> NumType add(NumType a, NumType b) { return a + b; } will work for add<int>(23, 11); but won't work for add<ostream>(cout, fout); Is what I am guessing is correct or ML type inference works differently? PS: Sorry for my poor English; it's not my native language.

    Read the article

  • Partial generic type inference possible in C#?

    - by Lasse V. Karlsen
    I am working on rewriting my fluent interface for my IoC class library, and when I refactored some code in order to share some common functionality through a base class, I hit upon a snag. Note: This is something I want to do, not something I have to do. If I have to make do with a different syntax, I will, but if anyone has an idea on how to make my code compile the way I want it, it would be most welcome. I want some extension methods to be available for a specific base-class, and these methods should be generic, with one generic type, related to an argument to the method, but the methods should also return a specific type related to the particular descendant they're invoked upon. Better with a code example than the above description methinks. Here's a simple and complete example of what doesn't work: using System; namespace ConsoleApplication16 { public class ParameterizedRegistrationBase { } public class ConcreteTypeRegistration : ParameterizedRegistrationBase { public void SomethingConcrete() { } } public class DelegateRegistration : ParameterizedRegistrationBase { public void SomethingDelegated() { } } public static class Extensions { public static ParameterizedRegistrationBase Parameter<T>( this ParameterizedRegistrationBase p, string name, T value) { return p; } } class Program { static void Main(string[] args) { ConcreteTypeRegistration ct = new ConcreteTypeRegistration(); ct .Parameter<int>("age", 20) .SomethingConcrete(); // <-- this is not available DelegateRegistration del = new DelegateRegistration(); del .Parameter<int>("age", 20) .SomethingDelegated(); // <-- neither is this } } } If you compile this, you'll get: 'ConsoleApplication16.ParameterizedRegistrationBase' does not contain a definition for 'SomethingConcrete' and no extension method 'SomethingConcrete'... 'ConsoleApplication16.ParameterizedRegistrationBase' does not contain a definition for 'SomethingDelegated' and no extension method 'SomethingDelegated'... What I want is for the extension method (Parameter<T>) to be able to be invoked on both ConcreteTypeRegistration and DelegateRegistration, and in both cases the return type should match the type the extension was invoked on. The problem is as follows: I would like to write: ct.Parameter<string>("name", "Lasse") ^------^ notice only one generic argument but also that Parameter<T> returns an object of the same type it was invoked on, which means: ct.Parameter<string>("name", "Lasse").SomethingConcrete(); ^ ^-------+-------^ | | +---------------------------------------------+ .SomethingConcrete comes from the object in "ct" which in this case is of type ConcreteTypeRegistration Is there any way I can trick the compiler into making this leap for me? If I add two generic type arguments to the Parameter method, type inference forces me to either provide both, or none, which means this: public static TReg Parameter<TReg, T>( this TReg p, string name, T value) where TReg : ParameterizedRegistrationBase gives me this: Using the generic method 'ConsoleApplication16.Extensions.Parameter<TReg,T>(TReg, string, T)' requires 2 type arguments Using the generic method 'ConsoleApplication16.Extensions.Parameter<TReg,T>(TReg, string, T)' requires 2 type arguments Which is just as bad. I can easily restructure the classes, or even make the methods non-extension-methods by introducing them into the hierarchy, but my question is if I can avoid having to duplicate the methods for the two descendants, and in some way declare them only once, for the base class. Let me rephrase that. Is there a way to change the classes in the first code example above, so that the syntax in the Main-method can be kept, without duplicating the methods in question? The code will have to be compatible with both C# 3.0 and 4.0. Edit: The reason I'd rather not leave both generic type arguments to inference is that for some services, I want to specify a parameter value for a constructor parameter that is of one type, but pass in a value that is a descendant. For the moment, matching of specified argument values and the correct constructor to call is done using both the name and the type of the argument. Let me give an example: ServiceContainerBuilder.Register<ISomeService>(r => r .From(f => f.ConcreteType<FileService>(ct => ct .Parameter<Stream>("source", new FileStream(...))))); ^--+---^ ^---+----^ | | | +- has to be a descendant of Stream | +- has to match constructor of FileService If I leave both to type inference, the parameter type will be FileStream, not Stream.

    Read the article

  • calling template function without <>; type inference

    - by Oops
    Hi, 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 explicitely 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 have to specify at least 1 typename, always? I assume the reason is because C++ can not distinguish functions between different return types, true? but if I use a void function and handover a reference, again I must not explicitely specify the return typename: template < typename TOut, typename TIn > void round( TOut & vret, TIn vin ) { vret = (TOut)(vin + 0.5); } double d = 1.54; int i; round(i, d); //no explicit <int> should the conclusion be to avoid functions with return and more prefer void functions that return via a reference when writing templates? Or is there a possibility to avoid explicitely writing the return type? something like "type inference" for templates... is "type inference" possible in C++0x? I hope I was not too unclear. many thanks in advance Oops

    Read the article

  • implementing type inference

    - by deepblue
    well I see some interesting discussions here about static vs. dynamic typing I generally prefer static typing, due to compile type checking, better documented code,etc. However I do agree that they do clutter up the code if done the way Java does it, for example. so Im about to start building a language of my own and type inference is one of the things that I want to implement, in a functional style language... I do understand that it is a big subject, and Im not trying to create something that has not been done before, just basic inferencing... any pointers on what to read up that will help me with this? preferably something more pragmatic/practical as oppose to more theoretical category theory/type theory texts. If there's a implementation discussion text out here, with data structures/algorithms, that would just be lovely much appreciated

    Read the article

  • Haskell: type inference and function composition

    - by Pillsy
    This question was inspired by this answer to another question, indicating that you can remove every occurrence of an element from a list using a function defined as: removeall = filter . (/=) Working it out with pencil and paper from the types of filter, (/=) and (.), the function has a type of removeall :: (Eq a) => a -> [a] -> [a] which is exactly what you'd expect based on its contract. However, with GHCi 6.6, I get gchi> :t removeall removeall :: Integer -> [Integer] -> [Integer] unless I specify the type explicitly (in which case it works fine). Why is Haskell inferring such a specific type for the function?

    Read the article

  • Help with possible Haskell type inference quiz questions

    - by Linda Cohen
    foldr:: (a -> b -> b) -> b -> [a] -> b map :: (a -> b) -> [a] -> [b] mys :: a -> a (.) :: (a -> b) -> (c -> a) -> c -> b what is inferred type of: a.map mys :: b.mys map :: c.foldr map :: d.foldr map.mys :: I've tried to create mys myself using mys n = n + 2 but the type of that is mys :: Num a => a -> a What's the difference between Num a = a - a and just a - a? Or what does 'Num a =' mean? Is it that mys would only take Num type? So anyways, a) I got [a] - [a] I think because it would just take a list and return it +2'd according to my definition of mys b) (a - b) - [a] - [b] I think because map still needs take both arguments like (*3) and a list then returns [a] which goes to mys and returns [b] c) I'm not sure how to do this 1. d) I'm not sure how to do this 1 either but map.mys means do mys first then map right? Are my answers and thoughts correct? If not, why not? THANKS!

    Read the article

  • Java Generics Class Parameter Type Inference

    - by Pindatjuh
    Given the interface: public interface BasedOnOther<T, U extends BasedList<T>> { public T getOther(); public void staticStatisfied(final U list); } The BasedOnOther<T, U extends BasedList<T>> looks very ugly in my use-cases. It is because the T type parameter is already defined in the BasedList<T> part, so the "uglyness" comes from that T needs to be typed twice. Problem: is it possible to let the Java compiler infer the generic T type from BasedList<T> in a generic class/interface definition? Ultimately, I'd like to use the interface like: class X implements BasedOnOther<BasedList<SomeType>> { public SomeType getOther() { ... } public void staticStatisfied(final BasedList<SomeType> list) { ... } } // Does not compile, due to invalid parameter count. Instead: class X implements BasedOnOther<SomeType, BasedList<SomeType>> { public SomeType getOther() { ... } public void staticStatisfied(final BasedList<SomeType> list) { ... } }

    Read the article

  • Java Generics Class Type Parameter Inference

    - by Pindatjuh
    Given the interface: public interface BasedOnOther<T, U extends BasedList<T>> { public T getOther(); public void staticStatisfied(final U list); } The BasedOnOther<T, U extends BasedList<T>> looks very ugly in my use-cases. It is because the T type parameter is already defined in the BasedList<T> part, so the "uglyness" comes from that T needs to be typed twice. Problem: is it possible to let the Java compiler infer the generic T type from BasedList<T> in a generic class/interface definition? Ultimately, I'd like to use the interface like: class X extends BasedOnOther<BasedList<SomeType>> { public SomeType getOther() { ... } public void staticStatisfied(final BasedList<SomeType> list) { ... } } Instead: class X extends BasedOnOther<SomeType, BasedList<SomeType>> { public SomeType getOther() { ... } public void staticStatisfied(final BasedList<SomeType> list) { ... } }

    Read the article

  • C# Generic method type argument inference

    - by CaptainCasey
    Is there any way that I can generalise the type definitions here? Ideally, I'd like to be able to change the type of 'testInput' and have test correctly infer the type at compile time. public static void Run() { var testInput = 3; var test = ((Func<int, int>) Identity).Compose<int,int,int>(n => n)(testInput); Console.WriteLine(test); } public static Func<T, V> Compose<T, U, V>(this Func<U, V> f, Func<T, U> g) { return x => f(g(x)); } public static T Identity<T> (this T value) { return value; }

    Read the article

  • Why doesn't C# do "simple" type inference on generics?

    - by Ken Birman
    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 subtyping at all: if Foo<T> is a 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 that Foo<int> is a subtype of Foo<T> and it would be trivial to check. Same for checking against Foo<Object>. So is there some other deep horror that would creep forth from the abyss if they were to just say, aw shucks, we'll do what we can? Or is this just some sort of religious purity on the part of the language guys at Microsoft?

    Read the article

  • Scala type inference failure on "? extends" in Java code

    - by oxbow_lakes
    I have the following simple Java code: package testj; import java.util.*; public class Query<T> { private static List<Object> l = Arrays.<Object>asList(1, "Hello", 3.0); private final Class<? extends T> clazz; public static Query<Object> newQuery() { return new Query<Object>(Object.class); } public Query(Class<? extends T> clazz) { this.clazz = clazz; } public <S extends T> Query<S> refine(Class<? extends S> clazz) { return new Query<S>(clazz); } public List<T> run() { List<T> r = new LinkedList<T>(); for (Object o : l) { if (clazz.isInstance(o)) r.add(clazz.cast(o)); } return r; } } I can call this from Java as follows: Query<String> sq = Query.newQuery().refine(String.class); //NOTE NO <String> But if I try and do the same from Scala: val sq = Query.newQuery().refine(classOf[String]) I get the following error: error: type mismatch found :lang.this.class[scala.this.Predef.String] required: lang.this.class[?0] forSome{ type ?0 <: ? } val sq = Query.newQuery().refine(classOf[String]) This is only fixed by the insertion of the correct type parameter! val sq = Query.newQuery().refine[String](classOf[String]) Why can't scala infer this from my argument? Note I am using Scala 2.7

    Read the article

  • Which knowledge base/rule-based inference engine to choose for real time Runway incursion prevention

    - by Piligrim
    Hello, we are designing a project that would listen to dialog between airport controllers and pilots to prevent runway incursions (eg. one airplane is taking off while other is crossing the runway). Our professor wants us to use Jena for knowledge base (or anything else but it should be some sort of rule-based engine). Inference is not the main thing in Jena and there's not much documentation and examples of this. So we need an engine that would get messages from pilots as input and output possible risks of incursion or any other error in message protocol. It should be easy to write rules, and should be easy to provide engine with real time data. I image it something like this: A pilot sends a message that he lands on some runway, the system remembers that the runway is busy and no one should cross it If someone is given an instruction to cross this runway, the engine should fire a rule that something is wrong When the pilot sends a message that he left the runway and goes to the gate, the system clears the runway and lets other planes to use it. So is Jena, or prolog or any other rules engine suitable for this? I mean it is suitable, but do we really need to use it? I asked the prof. if we could just keep state of the runway and use some simple checks based on messages we receive and he said that it is not scalable and we need the knowledge base. Can someone give me any advise on which approach to use for this system? If you recommend k.b., then which one should we use? The project is written in java. Thank you.

    Read the article

  • Covariance and Contravariance type inference in C# 4.0

    - by devoured elysium
    When we define our interfaces in C# 4.0, we are allowed to mark each of the generic parameters as in or out. If we try to set a generic parameter as out and that'd lead to a problem, the compiler raises an error, not allowing us to do that. Question: If the compiler has ways of inferring what are valid uses for both covariance (out) and contravariance(in), why do we have to mark interfaces as such? Wouldn't it be enough to just let us define the interfaces as we always did, and when we tried to use them in our client code, raise an error if we tried to use them in an un-safe way? Example: interface MyInterface<out T> { T abracadabra(); } //works OK interface MyInterface2<in T> { T abracadabra(); } //compiler raises an error. //This makes me think that the compiler is cappable //of understanding what situations might generate //run-time problems and then prohibits them. Also, isn't it what Java does in the same situation? From what I recall, you just do something like IMyInterface<? extends whatever> myInterface; //covariance IMyInterface<? super whatever> myInterface2; //contravariance Or am I mixing things? Thanks

    Read the article

  • Covariance and Contravariance inference in C# 4.0

    - by devoured elysium
    When we define our interfaces in C# 4.0, we are allowed to mark each of the generic parameters as in or out. If we try to set a generic parameter as out and that'd lead to a problem, the compiler raises an error, not allowing us to do that. Question: If the compiler has ways of inferring what are valid uses for both covariance (out) and contravariance(in), why do we have to mark interfaces as such? Wouldn't it be enough to just let us define the interfaces as we always did, and when we tried to use them in our client code, raise an error if we tried to use them in an un-safe way? Example: interface MyInterface<out T> { T abracadabra(); } //works OK interface MyInterface2<in T> { T abracadabra(); } //compiler raises an error. //This makes me think that the compiler is cappable //of understanding what situations might generate //run-time problems and then prohibits them. Also, isn't it what Java does in the same situation? From what I recall, you just do something like IMyInterface<? extends whatever> myInterface; //covariance IMyInterface<? super whatever> myInterface2; //contravariance Or am I mixing things? Thanks

    Read the article

  • Scala: Correcting type inference of representation type over if statement

    - by drhagen
    This is a follow-up to two questions on representation types, which are type parameters of a trait designed to represent the type underlying a bounded type member (or something like that). I've had success creating instances of classes, e.g ConcreteGarage, that have instances cars of bounded type members CarType. trait Garage { type CarType <: Car[CarType] def cars: Seq[CarType] def copy(cars: Seq[CarType]): Garage def refuel(car: CarType, fuel: CarType#FuelType): Garage = copy( cars.map { case `car` => car.refuel(fuel) case other => other }) } class ConcreteGarage[C <: Car[C]](val cars: Seq[C]) extends Garage { type CarType = C def copy(cars: Seq[C]) = new ConcreteGarage(cars) } trait Car[C <: Car[C]] { type FuelType <: Fuel def fuel: FuelType def copy(fuel: C#FuelType): C def refuel(fuel: C#FuelType): C = copy(fuel) } class Ferrari(val fuel: Benzin) extends Car[Ferrari] { type FuelType = Benzin def copy(fuel: Benzin) = new Ferrari(fuel) } class Mustang(val fuel: Benzin) extends Car[Mustang] { type FuelType = Benzin def copy(fuel: Benzin) = new Mustang(fuel) } trait Fuel case class Benzin() extends Fuel I can easily create instances of Cars like Ferraris and Mustangs and put them into a ConcreteGarage, as long as it's simple: val newFerrari = new Ferrari(Benzin()) val newMustang = new Mustang(Benzin()) val ferrariGarage = new ConcreteGarage(Seq(newFerrari)) val mustangGarage = new ConcreteGarage(Seq(newMustang)) However, if I merely return one or the other, based on a flag, and try to put the result into a garage, it fails: val likesFord = true val new_car = if (likesFord) newFerrari else newMustang val switchedGarage = new ConcreteGarage(Seq(new_car)) // Fails here The switch alone works fine, it is the call to ConcreteGarage constructor that fails with the rather mystical error: error: inferred type arguments [this.Car[_ >: this.Ferrari with this.Mustang <: this.Car[_ >: this.Ferrari with this.Mustang <: ScalaObject]{def fuel: this.Benzin; type FuelType<: this.Benzin}]{def fuel: this.Benzin; type FuelType<: this.Benzin}] do not conform to class ConcreteGarage's type parameter bounds [C <: this.Car[C]] val switchedGarage = new ConcreteGarage(Seq(new_car)) // Fails here ^ I have tried putting those magic [C <: Car[C]] representation type parameters everywhere, but without success in finding the magic spot.

    Read the article

  • What are some reasonable stylistic limits on type inference?

    - by Jon Purdy
    C++0x adds pretty darn comprehensive type inference support. I'm sorely tempted to use it everywhere possible to avoid undue repetition, but I'm wondering if removing explicit type information all over the place is such a good idea. Consider this rather contrived example: Foo.h: #include <set> class Foo { private: static std::set<Foo*> instances; public: Foo(); ~Foo(); // What does it return? Who cares! Just forward it! static decltype(instances.begin()) begin() { return instances.begin(); } static decltype(instances.end()) end() { return instances.end(); } }; Foo.cpp: #include <Foo.h> #include <Bar.h> // The type need only be specified in one location! // But I do have to open the header to find out what it actually is. decltype(Foo::instances) Foo::instances; Foo() { // What is the type of x? auto x = Bar::get_something(); // What does do_something() return? auto y = x.do_something(*this); // Well, it's convertible to bool somehow... if (!y) throw "a constant, old school"; instances.insert(this); } ~Foo() { instances.erase(this); } Would you say this is reasonable, or is it completely ridiculous? After all, especially if you're used to developing in a dynamic language, you don't really need to care all that much about the types of things, and can trust that the compiler will catch any egregious abuses of the type system. But for those of you that rely on editor support for method signatures, you're out of luck, so using this style in a library interface is probably really bad practice. I find that writing things with all possible types implicit actually makes my code a lot easier for me to follow, because it removes nearly all of the usual clutter of C++. Your mileage may, of course, vary, and that's what I'm interested in hearing about. What are the specific advantages and disadvantages to radical use of type inference?

    Read the article

  • Why is Delphi unable to infer the type for a parameter TEnumerable<T>?

    - by deepc
    Consider the following declaration of a generic utility class in Delphi 2010: TEnumerableUtils = class public class function InferenceTest<T>(Param: T): T; class function Count<T>(Enumerable: TEnumerable<T>): Integer; overload; class function Count<T>(Enumerable: TEnumerable<T>; Filter: TPredicate<T>): Integer; overload; end; Somehow the compiler type inference seems to have problems here: var I: Integer; L: TList<Integer>; begin TEnumerableUtils.InferenceTest(I); // no problem here TEnumerableUtils.Count(L); // does not compile: E2250 There is no overloaded version of 'Count' that can be called with these arguments TEnumerableUtils.Count<Integer>(L); // compiles fine end; The first call works as expected and T is correctly inferred as Integer. The second call does not work, unless I also add <Integer -- then it works, as can be seen in the third call. Am I doing something wrong or is the type inference in Delphi just not supporting this (I don't think it is a problem in Java which is why expected it to work in Delphi, too).

    Read the article

  • Type-inferring a constant in C#

    - by Andreas Grech
    In C#, the following type-inference works: var s = "abcd"; But why can't the type be inferred when the variable is a constant? The following throws a compile-time exception: const var s = "abcd"; // <= Compile time error: // Implicitly-typed local variables cannot be constant

    Read the article

  • error: polymorphic expression with default arguments

    - by 0__
    This following bugs me: trait Foo[ A ] class Bar[ A ]( set: Set[ Foo[ A ]] = Set.empty ) This yields <console>:8: error: polymorphic expression cannot be instantiated to expected type; found : [A]scala.collection.immutable.Set[A] required: Set[Foo[?]] class Bar[ A ]( set: Set[ Foo[ A ]] = Set.empty ) ^ It is quite annoying that I have to repeat the type parameter in Set.empty. Why does the type inference fail with this default argument? The following works: class Bar[ A ]( set: Set[ Foo[ A ]] = { Set.empty: Set[ Foo[ A ]]}) Please note that this has nothing to do with Set in particular: case class Hallo[ A ]() class Bar[ A ]( hallo: Hallo[ A ] = Hallo.apply ) // nope Strangely not only this works: class Bar[ A ]( hallo: Hallo[ A ] = Hallo.apply[ A ]) ...but also this: class Bar[ A ]( hallo: Hallo[ A ] = Hallo() ) // ???

    Read the article

  • Use of var keyword in C#

    - by kronoz
    After discussion with colleagues regarding the use of the 'var' keyword in C# 3 I wondered what people's opinions were on the appropriate uses of type inference via var? For example I rather lazily used var in questionable circumstances, e.g.:- foreach(var item in someList) { // ... } // Type of 'item' not clear. var something = someObject.SomeProperty; // Type of 'something' not clear. var something = someMethod(); // Type of 'something' not clear. More legitimate uses of var are as follows:- var l = new List<string>(); // Obvious what l will be. var s = new SomeClass(); // Obvious what s will be. Interestingly LINQ seems to be a bit of a grey area, e.g.:- var results = from r in dataContext.SomeTable select r; // Not *entirely clear* what results will be here. It's clear what results will be in that it will be a type which implements IEnumerable, however it isn't entirely obvious in the same way a var declaring a new object is. It's even worse when it comes to LINQ to objects, e.g.:- var results = from item in someList where item != 3 select item; This is no better than the equivilent foreach(var item in someList) { // ... } equivilent. There is a real concern about type safety here - for example if we were to place the results of that query into an overloaded method that accepted IEnumerable<int> and IEnumerable<double> the caller might inadvertently pass in the wrong type. Edit - var does maintain strong typing but the question is really whether it's dangerous for the type to not be immediately apparent on definition, something which is magnified when overloads mean compiler errors might not be issued when you unintentionally pass the wrong type to a method. Related Question: http://stackoverflow.com/questions/633474/c-do-you-use-var

    Read the article

  • Problem in inferring instances that have integer cardinality constraint

    - by Mikae Combarado
    Hello, I have created an RDF/OWL file using Protege 4.1 alpha. I also created a defined class in Protege called CheapPhone. This class has a restriction which is shown below : (hasPrice some integer[< 350]) Whenever, a price of a phone is below 350, it is inferred as CheapPhone. There is no problem for inferring this in Protege 4.1 alpha. However, I cannot infer this using Jena. I also created a defined class called SmartPhone. This class also has a restriction which is shown below : (has3G value true) and (hasInternet value true) Whenever, a phone has 3G and Internet, it is inferred as SmartPhone. In this situation, there is no problem inferring this in both Protege and Jena. I have started to think that there is a problem in default inference engine of Jena. The code that I use in Java is below : Reasoner reasoner = ReasonerRegistry.getOWLReasoner(); reasoner = reasoner.bindSchema(ontModel); OntModelSpec ontModelSpec = OntModelSpec.OWL_MEM_MINI_RULE_INF; ontModelSpec.setReasoner(reasoner); // Create ontology model with reasoner support // ontModel was created and read before, so I don't share the code in order // not to create garbage here OntModel model = ModelFactory.createOntologyModel(ontModelSpec, ontModel); OntClass sPhone = model.getOntClass(ns + "SmartPhone"); ExtendedIterator s = sPhone.listInstances(); while(s.hasNext()) { OntResource mp = (OntResource)s.next(); System.out.println(mp.getURI()); } This code works perfectly and returns me the instances, but when I change the code below and make it appropriate for CheapPhone, it doesn't return anything. OntClass sPhone = model.getOntClass(ns + "CheapPhone"); Am I doing something wrong ?

    Read the article

1 2 3 4  | Next Page >