typesystem

Best way to check if System.Type is a descendant of a given class

Consider the following code: public class A { } public class B : A { } public class C : B { } class D { public static bool IsDescendantOf(this System.Type thisType, System.Type thatType) { /// ??? } void Main() { A cValue = new C(); C.GetType().IsDescendantOf(cValue.GetT...

type of system.Collection <T>

I'm creating a list of <T>, but i want to know the type of that T-object. (i'm using reflection in my project, so i don't know the type when i'm creating my code. So first i have my List --> List<T> values Now i want to get all the properties of that T-object (for creating columns in a datagrid) any help? ...

Ocaml Int and negative values

Given this snippet of OCaml code: let rec range a b = if a > b then [] else a :: range (a+1) b ;; The Repl tells me that it's type is: val range : int -> int -> int list = <fun> Giving it inputs such as: range 0 4;; gives back the list: - : int list = [0; 1; 2; 3; 4] However providing the input range -4 2;; Gives the...

An error with Haskell classes I fall all the time and can't understand

Hi, there's an error I come across all the time but can't understand how to make it right. An example of code that gives me this error is: class Someclass a where somefunc :: (Num b) => b -> a -> a data Sometype = Somecons Int instance Someclass Sometype where somefunc x (Somecons y) = Somecons (x+y) The error message is: ...

Accessing type members outside the class in Scala

Hi, I am trying to understand type members in Scala. I wrote a simple example that tries to explain my question. First, I created two classes for types: class BaseclassForTypes class OwnType extends BaseclassForTypes Then, I defined an abstract type member in trait and then defined the type member in a concerete class: trait ScalaT...

Can one create Sized Types in Scala?

Is it possible to create types like e.g. String(20) in scala? The aim would be to have compiler checks for things like: a: String(20) b: String(30) a = b; // throws a compiler exception when no implicit conversion is available b= a; // works just fine Note: It doesn't need to be/named String ...

F# return type coercion

Hi, In F# I have a function that returns System.Linq.Expression instances: and System.Object with member this.ToExpression() = match this with | :? System.Int32 -> Expression.Constant(this) :> Expression | :? System.Boolean -> Expression.Constant(this) :> Expression | :? Tml.Runtime.Seq as s -> s.ToExpression() |...

HowTo get the class of _ :Any

I've wrapped a Message and would like to log which message I've wrapped. val any :Any = msg.wrappedMsg var result :Class[_] = null The only solution I could find is matching everything: result = any match { case x:AnyRef => x.getClass case _:Double => classOf[Double] case _:Float => classOf[Float] case _:Long => classOf[Lo...

C#: using type of "self" as generic parameter?

This may seem a bit odd, but I really need to create a workaround for the very complicated duplex - communication - handling in C#, especially to force other developers to observe the DRY - principle. So what I'm doing is to have a type based multiton that looks like this: internal sealed class SessionManager<T> where T : DuplexService...

Would .NET be able to function just as well without the use of type Object?

I am asking this because it seems like using Object seems to be an easy way out to solve certain problems, like "I don't have a specific type, so use Object", etc. Also the reason this made me curious is because a colleague of mine told me that if .NET was a true object-oriented platform then it wouldn't have to have a catch all type li...

How does custom F# types map to CLR types?

I don't know if the title of the question is clear but I am wondering the actual types of custom F# types. Like in C#, there are value types and reference types. For F#, is there a single type that governs the type system? Are they all value types (since they are immutable by default)? Or is/are there completely new types that's nothi...

Can a type be a reference type and a value type at the same time?

If not and the set of reference types and value types are mutually exclusive, why doesn't this compile: public static void Do<T>(T obj) where T : struct { } public static void Do<T>(T obj) where T : class { } The compiler states: "Type already defines a member called 'Do' with the same parameter types.", but T and T are not the same h...