[Haskell-cafe] Re: Type system speculation

Andrew Coppin andrewcoppin at btinternet.com
Thu Dec 10 15:46:59 EST 2009

oleg at okmij.org wrote:
> Andrew Coppin wrote:
>> What we're really trying to do here is attach additional information to a
>> value - information which exists only in the type checker's head, but has no
>> effect on runtime behaviour.
> Haskell has had the ability to attach arbitrary many pieces of
> (type-level) data to arbitrary types for a long time -- ever since
> multi-parameter type classes and functional dependencies have been
> introduced. Nowadays, type families accomplish the same with fewer
> keystrokes. One merely needs to define a type family
> 	type family Attrib n index :: *
> which maps the existing type n and the index to an arbitrary type.

Ah, good point. I hadn't thought of that!

So it seems you can indeed attach arbitrary attributes to any type, any 
time. However, I don't immediately see a way to construct a "safe" 
string type and an "unsafe" string type, so that you can write code 
which distinguishes between them, but that existing code that just 
expects a plain ordinary string still works. You could newtype string as 
two new types and attach whatever attributes you want to these types, 
but then normal string functions wouldn't work. Any ideas?

More information about the Haskell-Cafe mailing list