[Haskell-beginners] dependent types
pat browne
Patrick.Browne at comp.dit.ie
Mon Jul 20 12:50:53 EDT 2009
{- Hi,
Consider the following Haskell data, class and instance definitions
The intended semantics are:
Two objects are equal if they have the same name.
The type of the name depends on the type of the object
-}
data Object a = Object a
class Named o n | o -> n where
name :: o -> n
instance (Eq n, Named o n) => Eq o where
o1 == o2 = name(o1) == name(o2)
{-
I have three questions about these definitions.
1) Does the above code capture the intended meaning?
2) Does Object a *fit* the Named class?,
or do I need a different sort of Object?
3) How would I write an instance of Named that implements the name
function correctly. Thomson[1] shows how to do this for non-dependent types
[1]Haskell: The Craft of Functional Programming, Second Edition, Page 272
-}
More information about the Beginners
mailing list