We have all seen integer, floating point, string, and the occasional decimal type. What are some of the most strange or unique or useful types you have encountered, useful or not?
|
closed as not constructive by Mark Trapp Jan 13 '12 at 20:32
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.
|
I'll be short:
in Haskell. With this simple construct, the language solves the issue of crashes or Frankly, an optional presence checked at compile-time ? It's dreamlike... |
||||
|
|
|
Felix has anonymous sum types. The type is written like:
as it would be in theory. The values are ugly:
except perhaps for a unit sum such as
which unfortunately uses zero origin counting for "C compatibility". Anonymous sums are necessary for structurally typed algebraic types, for example:
is a (singly linked) list of T. All other languages I know of required nominally typed sums, where both the type itself and the constructors must be given names. The shorthand 3 used above is cute, the following is in the library:
and this notation:
is an array of static length 3 .. the 3 is not an integer but a sum of 3 units. What a pity + is not associative :) |
||||
|
|
|
Googles Go has a "Channel" type which is quite unique. |
||||
|
|
|
If you want a language with a unique type then head for BCPL. This language only has one data type, the word, being a fixed number of bits for the language implementation. |
||||
|
|
|
Clojure is interesting because it has a meta-concept of "abstractions" that pervade the language. Examples:
To some extent, the abstractions take the "single responsibility principle" to the extreme. It's up to you to compose them to get the functionality that you want, but you can be extremely flexible about how you glue them together. For example, if you want a class-based OOP system with inheritance, you could build one out of these core abstractions relatively quickly. In practice, the abstractions themselves are designed in a way that multiple implementations are possible, e.g. through specific interfaces like clojure.lang.ISeq for sequences or clojure.lang.IFn for higher order functions. There's an interesting video about this topic: The Art of Abstraction |
||||
|
|
|
VHDL has physical types. A literal of such type includes both a value and a unit. You can define subunits as well. For instance, a predefined physical type is
Together with operator overloading, you can define very interesting things. |
||||
|
|
|
Delphi has sets (see also), which I don't believe are implemented the same way in other languages. This makes storing multi-variable attributes in databases a breeze :D |
||||
|
|
|
Ruby's |
||||
|
|
|
Lisp has two interesting types: |
||||
|
|
|
I am perennially fond of |
|||||||||
|
|
I suppose it's really only strange coming from programming on a classical architecture, but certainly one of the hardest types for me to wrap my head around at first was the quantum register, which shows up in QCL. |
||||
|
|
|
A handful of languages in the functional family have a class of types known as Unity. The distinguishing feature of Unity types are that they contain no information, they are zero bit types. A unity type (in some variations) is also its only value, or (in most others) has only one value (that is not itself a type). These are useful, though, because they are distinguished types. Since you can't implicitly convert from one unity type to another, you can put static type checking to work in a very efficient, and expressive way. Unity is also the way most such languages describe Enums, by allowing a new type to be any of a defined set of other types, or to describe maybe types, values that may be either a value of a typical type (say, an integer), or have a value that represents no-value. Some languages that don't employ the richness of user defined unity types still have unity in them, in some form or another. For instance, Python has at least three unity types, Other interesting examples of unity include |
||||
|
|
|
Clipper had 'Code Blocks', which were similar to anonymous methods. They could be passed around and evaluated as needed, usually as a form of a callback. You'd often use them for things like performing calculations on the fly when presenting tables of data. |
||||
|
|
Regular Expressions:They are extremely powerful yet compact objects. |
|||||
|
|
COBOL. Essentially only two basic data types, strings and numbers, but you have to specify exactly how they're laid out in memory, e.g. |
||||
|
|
|
Fortran has common blocks; it's one of the least common data types in modern languages, or, rather an unusual way to efficiently share data. Fortran 95 has interval types and built-in interval arithmetics. The list would not be complete without monadic types found in Haskell. To understand them you need a bit of effort. |
|||||
|
|
I'm still trying to wrap my head around what a multi-parameter function becomes in F# and other functional languages. Basically int f(Foo, Bar) becomes func f(Foo) That is the two parameter function that takes a Foo, and a Bar and returns an int is really a one parameter function that takes a Foo and returns a one parameter function that takes a bar and returns an int. But somehow you can call it with two parameters if you want. I wrote a post about it here |
|||||
|
|
I found union's in C++ to be 'quirky' when I first heard about them. I still haven't hit a scenario where they're the obvious choice to implement. |
|||||||||
|
|
Lua has a built-in table that is most impressive. It has a built-in hashtable and a vector, and with the use of metatables can be the fundamental base for object-oriented programming in a procedural language. Each index of a table can receive any of the basic language structures (number, boolean, string, function -yes, functions are types on lua -, and tables). |
||||
|
|
|
q/kdb+ has tables built-in. Since it's a programming language and column-oriented database in one, there's no need for LINQ or ORMs. For example, can create a table like this (assignment is distinquished by
Now I can look at my table:
And I can query it:
|
||||
|
|
|
I had a soft spot in my heart for Euphoria's data types when I was younger It is structured as thus:
Note: "jon" is actually a short hand way of writing the sequence of ASCII values. For example |
|||||||||
|
|
PL/SQL lets you declare variables of type And C# lets you declare objects as nullable or not, though I'm not sure that counts as a type. |
|||||
|