[Haskell-beginners] Type of a Group.

Robert Goss goss.robert at gmail.com
Sat Feb 9 22:16:57 CET 2013

First thank you for your reply.

Yes that is roughly got with my first attempt. The issue I have with it 
is that i need a new data type for each cyclic group still unless I have 
missed something.

The implementation that I wrote for the second type I mentioned is the 

{-# LANGUAGE MultiParamTypeClasses #-}

class Group g x where
   mul :: g -> x -> x -> x
   inv :: g -> x -> x
   unit :: g -> x

class (Group g x) => FGGroup g x where
   gens :: g -> [x]

newtype Cyclic = Cyclic Int deriving (Eq)

cyclic :: Int -> Cyclic
cyclic n = Cyclic n

instance Group Cyclic Int where
   unit _ = 0
   mul (Cyclic n) x y = (x+y) `mod` n
   inv (Cyclic n) x = n - x

instance FGGroup Cyclic Int where
   gens _ = [1]

All the best,


More information about the Beginners mailing list