
8 Sep
2010
8 Sep
'10
5:51 p.m.
Here's a different approach: If you just want to make the typechecker distinguish between some values but still have some functions that don't care what "subtype" they are, you can use phantom types: data Obj x = Obj X Y Z data BlogObj type Blog = Obj BlogObj data CommentObj type Comment = Obj CommentObj data UserObj type User = Obj UserObj Now you can write a function that takes a Blog, and it will refuse other kinds of 'Obj'. But you can still write a function that takes 'Obj x' and it will accept any kind of Obj. So you don't need to do any unwrapping if you leave the functions that matter polymorphic.