Wiki
Version 15 (modified by Chuck, 15 years ago)

--

Cobra Types Overview

  • Primitive Types
    • Common
      • bool
      • char
      • int (= int32)
      • uint (= uint32)
      • float (= float64)
      • decimal
      • number (= decimal, change with -number: option)
      • dynamic (see DynamicType)
    • Explicit 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<of T>, Dictionary<of K, V>, Set<of T>
        • Stack<of T>, Queue<of T>
        • TextWriter, TextReader, StringWriter
    • Struct
      • No inheritance (other than Object)
      • Value-based
      • Popular structs
        • DateTime, Color (System.Drawing)
    • Interface
      • Multiple inheritance
      • No code implementation
      • Popular interfaces (provided by platform libraries)
        • IEnumerable, IEnumerable<of T> (but use T* instead; see streams below)
        • IComparable, IComparable<of T>
  • Nilable Type
    • foo? - can be "foo" or "nil"
    • applies 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"
    • You can make instances with a type at run-time
      • t = x.getType
      • 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<of int>, List<of String>, Dictionary<of String, int>
    • The general form is: Name<of T, U, ...>
    • You can declare your own
    • You can overload by number of type arguments. In other words, Foo<of T> and Foo<of T, U> are two different types.
    • Methods can be generic: def foo<of T>(a as T, b as T)
  • See also

TODO: arrays, passthrough, vari, greatest common denominator

See also: TypeInference, LanguageTopics, LibraryTopics