Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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?

share|improve this question

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 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, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

3  
Would anyone like to write the entry for Lisp? –  Mark C Jan 25 '11 at 1:59

24 Answers 24

I am perennially fond of void *. It's probably a symptom of something deeply flawed in me.

share|improve this answer
2  
Yes. I'm afraid that's exactly what it is. :) Oh, +1 for "interesting" rather than "unique". Objective-C obviously has void * and Pascal/Delphi have Pointer. –  Frank Shearar Jan 25 '11 at 9:03
14  
I just love the inherent pessimism it expresses: 'Can you see that thing over there?' 'Yes, what is it?', 'No idea.' –  biziclop Jan 25 '11 at 19:11

I'll be short:

Maybe a

in Haskell.

With this simple construct, the language solves the issue of crashes or NullPointerException, it neatly sidesteps the "One Million Mistake" of Tony Hoare :)

Frankly, an optional presence checked at compile-time ? It's dreamlike...

share|improve this answer

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).

share|improve this answer

I'm surprised nobody has mentioned Monads or Algebraic Datatypes yet.

share|improve this answer

SNOBOL: pattern (essentially a LL(1) parser tree, if I remember it correctly).

share|improve this answer

Lisp has two interesting types: t and nil. What's interesting about them is that everything is a t and nothing is a nil.

share|improve this answer

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.

share|improve this answer
1  
@MarkC IIRC its basically global data, but each function that accesses has to explicitly say it is going to at the top –  jk. Sep 27 '11 at 8:32

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

share|improve this answer

PL/SQL lets you declare variables of type my_table.some_column%type... I find that pretty damn useful.

And C# lets you declare objects as nullable or not, though I'm not sure that counts as a type.

share|improve this answer
4  
But cursor%rowtype is even funnier: it's a dynamically-formed record type that reflects which columns the cursor's query returns. –  9000 Jan 25 '11 at 0:36

I had a soft spot in my heart for Euphoria's data types when I was younger

It is structured as thus:

Object
-> Atom
-> Sequence
  • Atom = A single numeric value
  • Sequence = A sequence of Objects

    -- examples of atoms:
    
    0
    98.6
    -1e6
    
    -- examples of sequences:
    
    {2, 3, 5, 7, 11, 13, 17, 19}
    {1, 2, {3, 3, 3}, 4, {5, {6}}}
    {{"jon", "smith"}, 52389, 97.25}
    {}                        -- the 0-element sequence
    

    See: The Ref Manual

Note: "jon" is actually a short hand way of writing the sequence of ASCII values. For example "ABCDEFG" is the same as {65, 66, 67, 68, 69, 70, 71}

share|improve this answer
7  
This feels LISP-like... –  FrustratedWithFormsDesigner Jan 25 '11 at 5:43
1  
@FrustratedWithForms Same, I thought, "Hey, he said, 'Atom'! This looks like (a) Lisp but with unnecessary dividers. :P –  Mark C Jan 26 '11 at 4:54

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.

share|improve this answer

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 : rather than = as in most languages):

people:([]name:`Joe`Amy`Sarah; age:17 15 18; GPA:3.5 3.8 3.33)

Now I can look at my table:

q)show people
name  age GPA 
--------------
Joe   17  3.5 
Amy   15  3.8 
Sarah 18  3.33

And I can query it:

q)select from people where GPA>3.4
name age GPA
------------
Joe  17  3.5
Amy  15  3.8
share|improve this answer

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.

share|improve this answer
3  
Unions came from C. One good example is the zval struct in php. –  Martin Wickman Jan 25 '11 at 7:12
2  
I've used them in a Z80 emulator, to easily access the 16 bit registers as whole registers (HL, BC) and as 8-bit registers (H, L, B and C). This reflects how they're used in Z80 asm. Also in "variants", a class that can hold a value of different types (for example int/float) - not sure why I didn't use subclasses, but it made sense at the time :) –  ggambett Jan 25 '11 at 11:50

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

share|improve this answer
8  
Rather, a function f(Foo, Bar) is the same as function f(Foo) that returns another function f'(Bar) which returns the value what f(Foo, Bar) would return. That is, if you fix the 'Foo' argument, but not 'Bar', you have a function that does not depend on 'Foo' but still depends on the 'Bar' argument. This is typical for functional languages; it's called 'currying'. –  9000 Jan 25 '11 at 0:40

Regular Expressions:

They are extremely powerful yet compact objects.
Languages that have them built in have great ability to manipulate text (lets not hear the word parse they are not that good).

share|improve this answer
2  
It is entirely possible to parse many simple grammars with regexes. For instance, it's relatively trivial to parse an ini file with a minimum of logic on top of a set of regexes. The mistake a lot of people make is trying to parse very complex grammars with it (ie. XML/HTML). –  Matthew Scharley Jan 25 '11 at 5:33

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, NoneType, NotImplementedType, and EllipsisType. It's interesting that the first two both mean something like "No value", but the third is used in complex values (specifically, slice expressions) to represent interesting special cases.

Other interesting examples of unity include NULL in sql and undefined in javascript, but not void in C or C++. void fails. Even though it describes a value of no information, but no actual value can be of type void.

share|improve this answer

Felix has anonymous sum types. The type is written like:

typedef il = int + long;

as it would be in theory. The values are ugly:

case 0 of il (1)
case 1 of il (2L)

except perhaps for a unit sum such as 3 = 1 + 1 + 1

case 0 of 3
case 1 of 3 

which unfortunately uses zero origin counting for "C compatibility". Anonymous sums are necessary for structurally typed algebraic types, for example:

(1 + T * li) as li

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:

typedef void = 0;
typedef unit = 1;
typedef bool = 2;

and this notation:

 T ^ 3

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 :)

share|improve this answer

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. PIC S9(5)V99 COMP-3.

share|improve this answer

Ruby's symbol type is a bit unusual. It's essentially a string implementing the singleton pattern. Or something. So far, I've found the best uses for symbols are in tracking states and passing function names.

share|improve this answer

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.

share|improve this answer

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 time:

type time is range <machine dependant> to <machine dependant> 
units
  fs;
  ps = 1000 fs;
  ns = 1000 ps;
  us = 1000 ns;
  Ms = 1000 us;
  sec = 1000 ms;
  min = 60 sec;
  hr = 60 min;
end units;

Together with operator overloading, you can define very interesting things.

share|improve this answer

Clojure is interesting because it has a meta-concept of "abstractions" that pervade the language. Examples:

  • Collections
  • Sequences (lazy and non-lazy)
  • Higher Order Functions
  • Multimethods
  • Protocols
  • Managed references
  • Macros
  • various others.....

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

share|improve this answer

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.

share|improve this answer

Googles Go has a "Channel" type which is quite unique.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.