1

I'm trying to define a type alias for words of group elements. More specifically, I have defined a group class as

class Group a where
  identity :: a
  inverse :: a -> a
  (.*) :: a -> a -> a

and I want a type alias for a word in group elements where a word is a list of elements and exponents, something like

type (Group a) => Word = [(Group a, Int)]

This doesn't work. Is there some way to accomplish this in Haskell, or can you recommend another approach? Thanks!

  • 7
    why not just `type Word a = [(a, Int)]` and add the constraint to the functions that need it? There just to be a way to constraint data-types but it did not really work out (see: https://stackoverflow.com/questions/7438600/datatypecontexts-deprecated-in-latest-ghc-why) – Random Dev May 09 '21 at 12:11
  • 1
    On an unrelated note: consider `class Monoid a => Group a where inverse :: a -> a` instead of making up yet another set of names for the other two things. – Joseph Sible-Reinstate Monica May 09 '21 at 17:11
  • Ah okay, I'll omit the constraint from the typealias then. Thanks! – Nothingisreallyworking May 09 '21 at 17:53

0 Answers0