[Haskell-beginners] Question: Data Type for user selection
Hartmut
hartmut0407 at googlemail.com
Tue Aug 16 01:35:57 CEST 2011
Haskellers,
in the following testing code I want to model user selection criterias.
Explanation of the requirement:
- BasicSelect represents a single value (in the beginning: Number or String)
- ExtendedSelect is a single value plus a sign if selection is meant
inclusive or exclusive
- MultipleSelections is a set of ExtendedSelect's
I have some problems with that:
- The BasicSelect shall only accept SelectionNum's or SelectionStr's.
Currently it accepts anything?
- The MultipleSelections shall only accept EmptySel or references to
ExtendedSelect's.
Can anybody give me a hint how do this? Does this work with plain data
types?
Hartmut
module SelectionCriterias where
data InclusiveOrExclusive = Inclusive | Exclusive
data BasicSelect a = NumberSelect a | StringSelect a
data Num a => NumberSelect a = SelectionNum a
data Show a => StringSelect a = SelectionStr a
data ExtendedSelect a = ExtendedSelect {
basicSel :: BasicSelect a,
inclOrExcl :: InclusiveOrExclusive
}
data MultipleSelections a = EmptySel | SingleSel a | MultipleSel [a]
-----------------------------------------------------------------------------
-- Examples/Usage:
-- e1 :: BasicSelect Integer
e1 = NumberSelect 100
e2 = NumberSelect 110
-- e2 :: BasicSelect [Char]
e3 = StringSelect "test3"
e4 = StringSelect "test4"
e5 = StringSelect "test5"
-- f1 :: ExtendedSelect Integer
f1 = ExtendedSelect { basicSel = e1, inclOrExcl = Inclusive }
f2 = ExtendedSelect { basicSel = e2, inclOrExcl = Exclusive }
-- f2 :: ExtendedSelect [Char]
f3 = ExtendedSelect { basicSel = e3, inclOrExcl = Exclusive }
-- multi1 :: MultipleSelections a
multi1 = EmptySel
-- multi2 :: MultipleSelections (ExtendedSelect Integer)
multi2 = SingleSel f1
-- multi3 :: MultipleSelections (ExtendedSelect Integer)
multi3 = MultipleSel [f1,f2]
-- e.g. shall not be valid - because Bool not supported
multi4 = MultipleSel [True, False]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110816/9d7f58ea/attachment.htm>
More information about the Beginners
mailing list