KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
In Haskell, is there a way to limit a data type by the value of its components? I've drafted an example. Say you have a checkers game. A checker is either of the Black or White type. data CheckerType = BlackChecker | WhiteChecker deriving (Eq) data Checker = Checker CheckerType Int The game board for a checker game contains a set of Black checkers and White checkers. data GameBoard = GameBoard ([Checker]) ([Checker]) In the previous declaration, is there any way to enforce the Checkers in the first [Checker] to be of CheckerType black, and the second to be of the opposing type?
Tags (comma-separated)
Save Edits
Cancel