== Cobra Types Overview == * Primitive Types * Common * bool * char * character literals are single quoted and preceeded by a c. * For example {{{ var underscore as char = c'_' }}} * int (= '''int32''') * uint (= '''uint32''') * float (= '''float64''') * decimal * number (defaults to '''decimal''', Can change with compiler -number: option) * dynamic (see DynamicType) * Can be explicit wrt !Sizes/Sign * int8, int16, int32, int64 * uint8, uint16, uint32, uint64 * float32, float64 * PrimitiveTypeMembers * Complex Types * Class * Single inheritance * Heap-based * Popular classes (provided by platform) * Object, String, !StringBuilder, Exception * List, Dictionary, Set * Stack, Queue * !TextWriter, !TextReader, !StringWriter * Struct * No inheritance (other than Object) * Value-based * Popular structs (CLR) * !DateTime, Color (System.Drawing) * Interface * Multiple inheritance * No code implementation * Popular interfaces (provided by platform libraries) * IEnumerable, IEnumerable (but use T* instead; see streams below) * IComparable, IComparable * Mixins * Reusable code implementation ( of interface or abstract class or just some capability) * Not instantiated directly * class declares use of a mixin explicitly and the implementation is melded into the class implicitly. * Nilable Type * Specifies that a variable can be either that type or '''nil''' (no-valued, Null) * A nilable type is not directly assignable to a non nilable variable of the same Type * requires explicit casting to lose or gain nilability ( {{{ to !, to ? }}} ) * Foo? - indicates nilable type Foo - can be type "'''Foo'''" or "'''nil'''" * applicable to all types * "'''dynamic'''" implies "'''dynamic?'''" meaning you can always pass "'''nil'''" where "'''dynamic'''" is expected * Streams * foo* - walkable collection of zero or more objects of type foo * See StreamType * Working with types at run-time * You can get the type of "x" with "x.getType" (library call) or "x.typeOf" (cobra language extension) * You can make instances with a type at run-time {{{ #!cobra t = x.typeOf obj1 = t() obj2 = t(0, 0) }}} * Generics * Classes, interfaces and structs can all be generic -- parameterized by type. * These are identical to .NET generics as found in C# and VB. * Examples: List, List, Dictionary * The general form is: Name for a template where T and U are type placeholders. * example: {{{ class ATag }}} * A generic type is instantiated by using the same name with a concrete type replacing the type placeholders[[BR]] e.g {{{ ATag() }}} * You can declare your own and or instantiate generic template types defined locally or in platform libraries. * You can overload by number of type arguments. In other words, Foo and Foo are two different types. * Methods can be generic: def foo(a as T, b as T) * See also * [http://cobra-language.com/forums/viewtopic.php?f=4&t=291 Discussion on types] TODO: arrays, passthrough, vari, greatest common denominator See also: TypeInference, LanguageTopics, LibraryTopics