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 = someOb...
I was reading a research paper about Haskell and how HList is implemented and wondering when the techniques described are and are not decidable for the type checker. Also, because you can do similar things with GADTs, I was wondering if GADT type checking is always decidable.
I would prefer citations if you have them so I can read/unde...
I am testing a function called extractions that operates over any list.
extractions :: [a] -> [(a,[a])]
extractions [] = []
extractions l = extract l []
where extract [] _ = []
extract (x:xs) prev = (x, prev++xs) : extract xs (x : prev)
I want to test it, for example, with
import Test.QuickCheck.Batch
prop_len l = l...
I would like to know how to infer coercions (a.k.a. implicit conversions) during type inference. I am using the type inference scheme described in Top Quality Type Error Messages by Bastiaan Heeren, but I'd assume that the general idea is probably the same in all Hindley-Milner-esque approaches.
It seems like coercion could be treated a...
I have the following code:
using System;
using System.Linq;
using System.Linq.Expressions;
public class Program
{
public static void Main()
{
Descendant d = new Descendant();
d.TestMethod();
}
}
public class Base
{
protected void FigureItOut<TClass, TMember>(Expression<Func<TClass, TMember>> expr)
{...
So odd situation that I ran into today with OrderBy:
Func<SomeClass, int> orderByNumber =
currentClass =>
currentClass.SomeNumber;
Then:
someCollection.OrderBy(orderByNumber);
This is fine, but I was going to create a method instead because it might be usable somewhere else other than an orderBy.
private int ReturnNumber(So...
I'm having some trouble navigating Java's rule for inferring generic type parameters. Consider the following class, which has an optional list parameter:
import java.util.Collections;
import java.util.List;
public class Person {
private String name;
private List<String> nicknames;
public Person(String name) {
this(name,Coll...
Has anyone an idea how the type inference problem
E > hd (cons 1 nil) : α0
with the typing environment
E={
hd : list(α1 ) → α1 ,
cons : α2 → list(α2 ) → list(α2 ),
nil : list(α3 ),
1 : int
}
can be transferred in an unificat...
Given a grammar and the attached action code, are there any standard solution for deducing what type each production needs to result in (and consequently, what type the invoking production should expect to get from it)?
I'm thinking of an OO program and action code that employs something like c#'s var syntax (but I'm not looking for som...
I am wondering why the C# 3.0 compiler is unable to infer the type of a method when it is passed as a parameter to a generic function when it can implicitly create a delegate for the same method.
Here is an example:
using System;
class Test
{
static void foo(int x) { }
static void bar<T>(Action<T> f) { }
static void test(...
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 ...
I need to declare the query variable outside the switch statement that way I would only have one variable that would handle different result of the LINQ Query. Please see the code below. Problem here is that I cannot infer a variable without initializing it
var query;
Switch(filter)
{
case 1:
var query = from c in Customers
...
I'm curious as to how often experienced Haskell programmers really use type inference in practice. I often see it praised as an advantage over the always-explicit declarations needed in certain other languages, but for some reason (perhaps just because I'm new) it "feels" right to write a type signature just about all the time... and I'm...
My compiler behaves oddly when I try to pass a fixed-size array to a template function. The code looks as follows:
#include <algorithm>
#include <iostream>
#include <iterator>
template <typename TSize, TSize N>
void f(TSize (& array)[N]) {
std::copy(array, array + N, std::ostream_iterator<TSize>(std::cout, " "));
std::cout << s...
Title says it all, how good is C# type inference? I read somewhere that it's only for local variables? Does it work for class level attributes? For method signatures? Method return types? etc.
...
Given the following generic interface and implementing class:
public interface IRepository<T> {
// U has to be of type T of a subtype of T
IQueryable<U> Find<U>() where U : T;
}
public class PersonRepository : IRepository<Employee> {
}
How could I call the Find method without specififying U?
var repository = new EmployeeRe...
Hello,
I am trying to figure out how to define a function that works on multiple types of parameters (e.g. int and int64). As I understand it, function overloading is not possible in F# (certainly the compiler complains). Take for example the following function.
let sqrt_int = function
| n:int -> int (sqrt (float n))
| n:int6...
Notice the following code. The offending line has been commented out.
interface I<R> { }
class C : I<int> { }
class Program
{
private static void function<T, R>(T t) where T : class, I<R>
{
}
static void Main(string[] args)
{
// function(new C()); // wont compile
function<C, int>(new C());
}
}
...
Hi
I was wondering if it is possible, as my 5 minutes of experimentation proved fruitless.
I hoped it would be as easy as:
T Identity<T>(T t) { return t; }
But this fails to compile on generic methods taking Func parameters. Eg OrderBy. Even specifying type parameters (which is exactly what I want to avoid!), it fails to compile.
...
I'd like to know how do the member types work in Scala, and how should I associate types.
One approach is to make the associated type a type parameter. The advantages of this approach is that I can prescribe the variance of the type, and I can be sure that a subtype doesn't change the type. The disadvantages are, that I cannot infer the...