types

Why doesn't scala have C++-like const-semantics?

In C++. I can declare most things as const, for example: Variables: const int i=5; Scala has val i=5, however this will only prevent reassigning, not changing the object as the following exampe shows: C++: const int i[]={1,2,3,4}; i[2]=5; //error Scala: val a=Array(1,2,3,4) a(2)=5 //a is now Array(1, 2, 5, 4) It gets even worse with mem...

Prolog type checking

Is there a way to determine the type of an element within a list in Prolog? I know that variables aren't explicitly typed in Prolog, but I need to check whether an element is a number, a specific character, etc. How can this be accomplished? ...

Cannot add to current window in titanium appcelerator. Get type error

I just started learning titanium for mobile using the android. I followed all the install steps and got the hello world script to work just find in the android emulator. The problem is Im trying to use example code to see how it all works. The example code Im currently having problems with is: var win = Titanium.UI.currentWindow; v...

int[] type and documentation

Hi, I'm puzzled about arrays in C#. I can't find any documentation on MSDN about for example the object double[]. I do find documentation about int, array, collections, ... but can't find out of what type double[] is. If I do double[] a = new double[10]; a.GetType(), I find that the type of a is System.Double[] I believe that the type ...

Type comparison not returning expected result.

I am using the following code to compare types so that a DataContractSerializer will re-initialize with the correct type if necessary. private void InitializeSerializer(Type type) { if (this.serializer == null) { this.serializer = new DataContractSerializer(type); this.typeToSerialize = ty...

typeinfo / typeid output

I'm currently trying to debug a piece of simple code and wish to see how a specific variable type changes during the program. I'm using the typeinfo header file so I can utilise typeid.name(). I'm aware that typeid.name() is compiler specific thus the output might not be particularly helpful or standard. I'm using GCC but I cannot find...

Newbie f# question

I have a simple function call takes two tuples. Getting compiler error on type: module test open System.IO open System let side (x1,y1) (x2,y2) : float = Math.Sqrt((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)) let a = side ( 2s, 3s ) ( 1s, 2s ) Error 2 The type 'float' does not match the type 'int16' Not sure where it goes wrong. ...

type of class in python

why if I do: class C(): pass type(C()) I got: <type 'instance'>, but if I do: class C(object): pass type(c()) I got: <class '__main__.c'> ? The first is not very userfull ...

Scala recursive generics: Parent[Child] and Child[Parent]

Update: Clarified and expanded, since the original question was simplified too far I need a pair of traits, each of which refers to the other such that parent and child classes must relate to each other. trait Parent [C <: Child] { def foo(c: C) } trait Child [P <: Parent] { def parent: P = ... def bar = parent.foo(this) } Suc...

Communicating between C# and Visual C++ over IPC port (OR: Sharing a type between a Visual C++ DLL and a C# application)

I have a DLL written in Visual C++ and an application written in C#. The application that is written in C# already uses IPC between multiple instances of itself so that it only ever runs one instance (it attempts to start an IPC server, and if it can't assumes there's already one running, in which case it sends the command line argument...

What is the difference between "Real Types" and "Arithmetic Types" in C?

The C99 standard describes them as so: The integer and real floating types are collectively called real types. Integer and floating types are collectively called arithmetic types. Does this mean they're the same thing in C? Or are there any differences between them? ...

Java- Identifying ints and doubles

I want to write a conditional statement, depending on whether a variable is an int or double, i.e if (x is a double) do stuff else if(x is an int) do stuff else do stuff I know this might not be a good idea, but its my only choice for now. Is this possible? ...

Converting types in Java

Hi fellas, Java noob here, I have an Iterator<TypeA> that I want to convert to Iterator<TypeB>. TypeA and TypeB cannot be directly cast to each other but I can write a rule how to cast them. How can I accomplish this? Should I extend and override Iterator<TypeA>'s next, hasNext and remove methods? Thanks. ...

C macro computing the number of bytes that a given compile-time constant requires

Often I have some compile-time constant number that is also the upper limit of possible values assumed by the variables. And thus I'm interested in choosing the smallest type that can accomodate those values. For example I may know that variables will fit into <-30 000, 30 000> range, so when looking for a suitable type I would start wit...

change dtype of a single column in a 2d numpy array

I am creating a 2d array full of zeros with the following line of code: MyNewArray=zeros([4,12],float) However, the first column will need to be populated with string-type textual data, while all the other columns will need to be populated with numerical data that can be manipulated mathematically. How can I edit the code above so th...

Question about cl_mem in OpenCL

I have been using cl_mem in some of my OpenCL boilerplate code, but I have been using it through context and not a sharp understanding of what exactly it is. I have been using it as a type for the memory I push on and off the board, which has so far been floats. I tried looking at the OpenCL docs, but cl_mem doesn't show up (does it?). I...

Is there a way to get a Type from the namespace/type strings alone?

I am needing to reference a type in an external assembly. I know the namespace and the type name and I know the assembly will be in the GAC, but that's it. Is there a way to get this type. I see there's a way to get it from a GUID or Program ID which works for me, but I know the people who develop the external assembly may drift away ...

Type inference with mutual recursion

I've been thinking about how type inference works in the following OCaml program: let rec f x = (g x) + 5 and g x = f (x + 5);; Granted, the program is quite useless (looping forever), but what about the types? OCaml says: val f : int -> int = <fun> val g : int -> int = <fun> This would exactly be my intuition, but how does the typ...

C++ - mapping type to enum

Hello! Is is possible to make compilation-time Type -> Enum Series mapping? Illustrating with an example: Let's say, I have some Type and a enumerated value: typedef int Type; enum Enumerated { Enum1, Enum2, Enum3, Enum4 }; and now I somehow state the following: "let's associate Enum1 and Enum4 with type Type (don't know how to im...

PHP get content type

I was wondering if there is a way to find out if a given string is an image e.g. $a = 'php';// output false $b = 'jpg';// output true $c = 'js'; // output false $d = 'png';// output : true I know it can be done by checking it against an array but I am just wondering if there is a better solution. ...