I know I must be missing something really obvious here. B.GetInstance().Call() generates the error: Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved.
I'm using ...
if i do any isUpper "asBsd", i'll get True.
here, the second element to any is a string.
but, if i do this:
any ("1" `isInfixOf`) ["qas","123","=-0"]
the second element to any is a list of strings.
how and why this difference between those 2 functions?
another example.
if i write filter isUpper "asdVdf" , i'll get "V".
here, the se...
I've got a function which takes an input of type
('a * (float * 'b * float)) list
Where I'd obviously like to avoid having to explicitly include the type.
The problem is that I convert the second float to decimal, using the decimal function.
let v2 (_,(_,_,v)) = decimal v
So type inference defaults to seeing this:
('a * (float * ...
I would like make an extension method for the generic class A which takes yet another generictype (in this example TC), but i guess that aint possible?
class Program
{
static void Main(string[] args)
{
var a = new A<B, B>();
a.DoIt<B>();
}
}
static class Ext
{
public static A<TA, TB> DoIt<TA, TB, TC>(th...
Is it a common pattern/idiom to use free functions as pseudo-constructors to avoid having to explicitly specify template parameters?
For example, everyone knows about std::make_pair, which uses its parameters to deduce the pair types:
template <class A, class B>
std::pair<A, B> make_pair(A a, B b)
{
return std::pair<A, B>(a, b);
}
/...
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<? ext...
So I'm trying to learn more about lambda expressions. I read this question on stackoverflow, concurred with the chosen answer, and have attempted to implement the algorithm using a console app in C# using a simple LINQ expression.
My question is: how do I translate the "var result" of the lambda expression into a usable object that I c...
Hi.
I want to use object instances as modules/functors, more or less as shown below:
abstract class Lattice[E] extends Set[E] {
val minimum: E
val maximum: E
def meet(x: E, y: E): E
def join(x: E, y: E): E
def neg(x: E): E
}
class Calculus[E](val lat: Lattice[E]) {
abstract class Expr
case class Var(name: String) extends...
I have a problem using a parameterized class as the key-type of a Map. First create the parameterized class:
scala> sealed abstract class Foo[T]{ def t: T }
defined class Foo
Now create some imaginary collection of these across unknown parameters:
scala> var l: List[Foo[_]] = Nil
l: List[Foo[_]] = List()
Now create a Map to store ...
Does "Value Restriction" practically mean that there is no higher order functional programming?
I have a problem that each time I try to do a bit of HOP I get caught by a VR error. Example:
let simple (s:string)= fun rq->1
let oops= simple ""
type 'a SimpleType= F of (int ->'a-> 'a)
let get a = F(fun req -> id)
let oops2= get ""
...
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,...
I was playing around the other day with making a class to handle some arithmetic operations (yes, I know numeric is coming out in 2.8) and found myself wondering how to simplify the following:
def Foo[A]( _1:A, _2:A ) = (_1, _2) match{
case _1:Bar, _2:Bar => _1 + _2
case _1:Baff, _2:Baff => _1 push _2
case _, _ => None
}
s...
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;
So...
I would like to write an object generator for a templated RAII class -- basically a function template to construct an object using type deduction of parameters so the types don't have to be specified explicitly.
The problem I foresee is that the helper function that takes care of type deduction for me is going to return the object by ...
I have:
class A {
public:
B toCPD() const;
And:
template<typename T>
class Ev {
public:
typedef result_of(T::toCPD()) D;
After instantiating Ev<A>, the compiler says:
meta.h:12: error: 'T::toCPD' is not a type
neither decltype nor typeof work either.
...
Why does this work? I'm not complaining, just want to know.
void Test()
{
int a = 1;
int b = 2;
What<int>(a, b);
// Why does this next line work?
What(a, b);
}
void What<T>(T a, T b)
{
}
...
I am using the Entity Framework, ASP.NET and C#3.5
I borrowed the following code to make sorting possible using a sortExpression from a GridView instead of the property of an entity:
public static IEnumerable<T> Sort<T>(this IEnumerable<T> source, string sortExpression)
{
string[] sortParts = sortExpression.Split(' ');
...
I'm kind of new in Haskell and I have difficulty understanding how inferred types and such works.
map :: (a -> b) -> [a] -> [b]
(.) :: (a -> b) -> (c -> a) -> c -> b
What EXACTLY does that mean?
foldr :: (a -> b -> b) -> b -> [a] -> b
foldl :: (a -> b -> a) -> a -> [b] -> a
foldl1 :: (a -> a -> a) -> [a] -> a
What are the differenc...
I've got this code that works:
def testTypeSpecialization: String = {
class Foo[T]
def add[T](obj: Foo[T]): Foo[T] = obj
def addInt[X <% Foo[Int]](obj: X): X = {
add(obj)
obj
}
val foo = addInt(new Foo[Int] {
def someMethod: String = "Hello world"
})
foo.someMethod
}
But, I'd lik...
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 bet...