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.WriteLi...
I have the following haskell code:
fac n = product [1..n]
taylor3s w0 f f' f'' t h = w1 : taylor3s w1 f f' f'' (t+h) h
where hp i = h^i / fac i
w1 = w0 + (hp 1) * f t w0 + (hp 2) * f' t w0 + (hp 3) * f'' t w0
taylor_results = take 4 $ taylor3s 1 f f' f'' 1 0.25
where f t x = t^4 - 4*x/t
f' t x = 4*t^3 - 4*(f t x...
I'm working on a completion (intellisense) facility for C# in emacs.
The idea is, if a user types a fragment, then asks for completion via a particular keystroke combination, the completion facility will use .NET reflection to determine the possible completions.
Doing this requires that the type of the thing being completed, be know...
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 ...
I was just pottering about with Tony Morris' excellent exercise on catamorphisms, when I was pondering what was happening in the following situation...
def cata[X](some: A => X, none: => X): X
Let me now call this method as follows:
def isDefined: Boolean = cata( _ => true, false)
I was wondering whether the type inferencer determi...
When trying to compile the following code in LINQPad :
void Main()
{
DriveInfo.GetDrives().Select(GetProviderName).Dump();
}
static string GetProviderName(DriveInfo drive)
{
// some irrelevant WMI code...
}
I get the following error :
The type arguments for method 'System.Linq.Enumerable.Select(System.Collections.Generic....
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" com...
I don't understand the last line of the example on page 148 of the FCD (§7.6.1.2/4):
const int&& foo();
int i;
struct A { double x; };
const A* a = new A();
decltype(foo()) x1 = i; // type is const int&&
decltype(i) x2; // type is int
decltype(a->x) x3; // type is double
decltype((a->x)) x4 = x3; // type is co...
Should the following be compiled without needing an explicit type definition on this?
def prepList[B >: A](prefix: PlayList[B]) : PlayList[B] =
prefix.foldr(this: PlayList[B])((node, suffix) => suffix.prepNode(node))
It seems to me that the type should be able to inferred. Is this just a limitation in the Scala compiler, or is there...
Given the following two classes:
public class ABC
{
public void Accept(Ordering<User> xyz)
{
// Do stuff with xyz...
}
}
public class Ordering<TEntity>
where TEntity : class
{
private readonly Func<IQueryable<TEntity>, IOrderedQueryable<TEntity>> Transform;
private Ordering(Func<IQueryable<TEntity>,...
Edit:
This is indeed a bug in the compiler, I've opened a defect and got the following response.
Hello Motti,
Thank you for submitting this issue. As noted in the stackoverflow posting, this is a bug in our decltype implementation. Unfortunately, we cannot fix this bug in the next release of Visual Studio since the code is relativ...
The F# compiler appears to perform type inference in a (fairly) strict top-to-bottom, left-to-right fashion. This means you must do things like put all definitions before their use, order of file compilation is significant, and you tend to need to rearrange stuff (via |> or what have you) to avoid having explicit type annotations.
How h...
I find myself using a lot of nested maps, e.g a Map[Int, Map[String, Set[String]]], and I'd like to have new Maps, Sets, etc. created automatically when I access a new key. E.g. something like the following:
val m = ...
m(1992)("foo") += "bar"
Note that I don't want to use getOrElseUpdate here if I don't have to because it gets pretty...
Once again, I wish C++ had stronger typedefs:
#include <vector>
template<typename T>
struct A {
typedef std::vector<T> List;
};
template<typename T>
void processList(typename A<T>::List list) {
// ...
}
int main() {
A<int>::List list;
processList<int>(list); // This works.
processList(list); // This doesn't.
...
Given:
static TDest Gimme<TSource,TDest>(TSource source)
{
return default(TDest);
}
Why can't I do:
string dest = Gimme(5);
without getting the compiler error:
error CS0411: The type arguments for method 'Whatever.Gimme<TSource,TDest>(TSource)' cannot be inferred from the usage. Try specifying the type arguments explicitly....
Can anyone explain why the second example below won't compile?
'Test 2' gives "error FS0670: This code is not sufficiently generic. The type variable ^a could not be generalized because it would escape its scope.". I fail to understand this error message.
// Test 1
type test1<'a> = | A of 'a
with
override t.ToString() =
...
It normally seems the following is illegal:
class Foo a where
foo :: a -> b -> a
Which makes sense; how do we know what b is?
However, if we look at Functor's definition:
class Functor f where
fmap :: (a -> b) -> f a -> f b
we see a and b showing up even though we only specify f as a type variable. I'm guessing this is all...
Ok, I've been reading everything I can find on var, and I'm pretty sure I've got a handle on their basic behaviors and type inference. I've always been a big proponent of explicit types, so var makes me a little edgy when I'm reading code. So I have a couple of questions regarding its memory usage and the behavior of a variable declared ...
I have this test:
testReadFile = runTestTT $ TestLabel "InteractionDomain.readFileContentsToList" (TestList [
(TestLabel "testing infrastructure: read test file" (TestList [
TestCase (withTempFileContainingText (\fileHandle ->
assertEqual "contents as expected" "The dog barks at midnight." (do
co...
In my own code, and on numerous mailing list postings, I've noticed confusion due to Nothing being inferred as the least upper bound of two other types.
The answer may be obvious to you*, but I'm lazy, so I'm asking you*:
Under what conditions is inferring Nothing in this way the most desirable outcome?
Would it make sense to hav...