haskell-cafe@haskell.org
[Top] [All Lists]

Re: [Haskell-cafe] Re: Type system speculation

Subject: Re: [Haskell-cafe] Re: Type system speculation
From: Andrew Coppin
Date: Thu, 10 Dec 2009 20:46:59 +0000
oleg@xxxxxxxxx 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?

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@xxxxxxxxxxx
http://www.haskell.org/mailman/listinfo/haskell-cafe

<Prev in Thread] Current Thread [Next in Thread>