On 08/01/06, Brian Hulley <[EMAIL PROTECTED]> wrote: > For example, suppose I'm writing a module M that deals with grammar, where > the elements in a grammar rule are parameterised so that rules can be > written using strings but processed as if we'd used ints instead: > > data Element a = Terminal a | Nonterminal a | Action a > > data Rule a = Rule (Element a) [[Element a]] > > Now I want to convert elements and rules from a to Int, so at the moment I > have to write: > > convertElement :: Element a -> CM (Element Int) > ... > > convertRule :: Rule a -> CM (Rule Int) > > for some appropriate monad CM. > Whereas I would have much preferred to use just the word "convert" in both > cases. It is tremendously annoying to have to suffix everything with the > type name.
This is what typeclasses are for. class Convert c where convert :: c a -> CM (c Int) - Cale _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe