views:

137

answers:

4

Hi, I'm looking for programming languages that let you redefine their type system without having to hack into the compiler. Is there anything out there that allows you to do that?

Thanks

+2  A: 

In C you can use DEFINE to redefine everything.

#DEFINE int double

Whether it's good or bad you can find out here:

What is the worst real-world macros/pre-processor abuse you've ever come across?

Developer Art
I think it was here (or dailyWTF) that someone recently posted `#define TRUE FALSE //Have fun debugging, suckers!`
FrustratedWithFormsDesigner
Or, even better, use `typedef`
schnaader
I was looking for something more... sophisticated.
John Coentros
@John Coentros: You wanted something to do this at runtime, maybe?
FrustratedWithFormsDesigner
This doesn't change the *type system*, though, just some names. A real change would be to, *e.g.,* give C subtyping polymorphism.
Antal S-Z
+1  A: 

If you're talking about redefining an actual type system, like making a statically typed language dynamic or making a weakly-typed language strongly-typed, then no.

Practically every language lets you define your own types, so I don't think that's what you meant either.

The only thing I can think of that might fit into what you're asking about are Macros in Common Lisp, which let you extend the syntax. This might be able to acheive what you are looking for, but until you state what it is exactly you're looking for, I can't really elaborate.

Also OCaml and its related languages allow you to do some pretty cool things with types. You can basically define any kind of type you can think of and then match against it with pattern matching, which makes it especially good to write compilers in.

Kevin
A: 

Javascript, Ruby, and Smalltalk, just that i know of, allow you to do all kinds of stuff, even redefining on the fly what an Object can do. Perl allows you to redefine practically the whole language. Basically any decent scripting language, especially one that allows duck typing, should have equal power. But it seems to be really common among functional languages and those with functional abilities.

cHao
A: 

If I remember correctly, Ada have neat type-creation possibilities, specially for measures (for instance, defining a minimum and a maximum, checking operations between differents measures...). I've seen it quoted as an example to avoid very stupid bugs.

Raveline