[Haskell-beginners] share a record type

Kees Bleijenberg k.bleijenberg at inter.nl.net
Fri Jun 17 13:00:09 CEST 2011


I want to learn more about Haskell and I started with my Sudoku solver
 
class SudokuClass s  where
   initAreas :: s -> s
   createEmptySudoku :: s
   getBoardLength :: s -> Int
   setBoard :: s -> Board -> s
   getCellToAreas :: s ->CellToAreas
 ... other functions with default implementations
 
I created a Sudoku solver for 9x9 sudoku's.
 
data Sudoku9x9 = Sudoku9x9 {
   board :: Board,
   areas:: Areas,
   cellToAreas :: CellToAreas
} deriving (Show)
 
Board, Areas and CellToAreas are of type Map.
 
After that I create an instance:
instance SudokuClass Sudoku9x9 where
   initAreas s = .....
 
After implementing the 9x9 solver I wanted to create a second instance
SudokuTwins, that solves a different kind of sudoku, but uses the same
record:
 
data SudokuTwins = SudokuTwins {
   board :: Board,
   areas:: Areas,
   cellToAreas :: CellToAreas
} deriving (Show)
This is almost a copy of Soduku9x9 (right side of the =)
 
How can I express the fact that all sudoku solvers use the same recordtype?
Can I make a type of the record structure {board:: Board.... } and use it in
the constructor function or can I incorperate the recordtype in the class or
......?
 
Kees
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110617/251a0351/attachment.htm>


More information about the Beginners mailing list