
9 Feb
2013
9 Feb
'13
4:16 p.m.
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 following: {-# 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, Robert