Brian Hulley writes: > Also, as a second point, could functional dependencies in type > classes be written using a similar syntax eg instead of > > class Insert t c a | c a -> t where > insert :: t -> c a -> c a > > we could write: > > class Insert (h (c a)) c a where > insert :: h (c a) -> c a -> c a > > or > class Insert t@(h (c a)) c a where -- re-using as-pattern syntax > insert :: t -> c a -> c a > > to avoid having to have a special syntax just for functional > dependencies and/or to be able to write more complicated fundeps more > succinctly?
You might be interested in associated types and associated type synonyms[1]. These are alternatives to functional dependencies which are less powerful but possibly easier to use. (Of course, no Haskell compiler supports them.) For example: class Collection c where type Elem c insert :: Elem c -> c -> c ... instance Collection [a] where type Elem [a] = a insert = (:) ... Your example, in the syntax of associated type synonyms, would look something like this: class Insert c a where type T c a insert :: T c a -> c a -> c a [1]: <http://research.microsoft.com/Users/simonpj/papers/assoc-types/> -- David Menendez <[EMAIL PROTECTED]> | "In this house, we obey the laws <http://www.eyrie.org/~zednenem> | of thermodynamics!" _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe