[PRL] Joel on Software - Making Wrong Code Look Wrong
Paul A. Steckler
steck at stecksoft.com
Wed May 11 14:27:20 EDT 2005
> I wonder if you could also introduce a "label" mechanism into MrFlow,
> where you could tag values as having that label, and tag the basic
> operations with contracts describing what they require/provide with
> those labels.
Here's a cheap hack to add attributes to types in Haskell using
phantom types:
data MyString a = MyString { s :: String }
deriving (Eq,Show)
type Unsafe = MyString Int
type Safe = MyString [Int]
x :: Unsafe
x = MyString { s = "foo" }
y :: Safe
y = MyString { s = "foo" }
Then, x == x or y == y will type-check,
but not x == y.
The actual type parameters to MyType
are unimportant, as long as it differs
for Safe and Unsafe.
-- Paul
More information about the PRL
mailing list