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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -