Defining Data Structures/ Types In Haskell -
how possible define data structure in haskell, such there constraints/rules apply elements of structure, , able reflect in type.
for example, if have type made of list of type,
r = [x | x <- input, rule1, rule2, rule3].
in case, type of r list of elements of (type of x). saying this, loose rules. how possible retain information in type definition.
to give more concreteness question, take sudoko case. grid of sudoko list of rows, in turn list of cells. know, there constraints on values, frequency. when 1 expresses types, these constraints don't show in definition of type of grid , row.
or not possible?
thanks.
in example of sodoku, create data type has multiple constructors, each representing 'rule' or semantic property. i.e.
data sodokutype = notvalidatedrow | invalidrow | validrow
now in validation function return invalidrow
detect validation of sodoku rules, , validrow
detect successful row (or column or square etc). allows pattern match well.
the problem you're having you're not using types, you're using values. you're defining list of values, while list not values contains.
note example used not useful not contain information rows position or that, can define you'd like.
Comments
Post a Comment