[Haskell-beginners] Re: dependent types
Felipe Lessa
felipe.lessa at gmail.com
Mon Jul 20 17:39:50 EDT 2009
On Mon, Jul 20, 2009 at 05:46:14PM -0300, Maurício wrote:
> data (Eq a) => Object a = Object a
I'd rewrite this as
newtype Object a = Object a
> instance (Named a) => Eq a where
> (==) = equals
Be careful with this instance! (specially since this is
haskell-beginners)
> instance Named (Object Integer) where
> type NameType (Object Integer) = Integer
> name (Object i) = i
I'd rewrite this as
instance Eq a => Named (Object a) where
type NameType (Object a) = a
name (Object a) = a
instance Eq a => Eq (Object a) where
(==) = equals
However, I guess something like
data Name n a = Name n a
instance Functor (Name n) where
fmap f (Name n a) = Name n (f a)
instance Eq n => Named (Name n a) where
type NameType (Name n a) = n
name (Name n _) = n
instance Copointed (Name n) where
-- from category-extras
extract (Name _ a) = a
would be a whole lot more useful, no?
--
Felipe.
More information about the Beginners
mailing list