So, between BEGIN:VEVENT and END:VEVENT you have many key pairs. So write a keyValuePair rule that returns (key, value) . Now inside the rule for VEVENT you do many KeyValuePair to get a list of pairs. After you have done this, you use the fold to populate the VEVENT record with the given values. In the function that you give to reset, you use pattern matching to find out in which field the value is stored. You use the VEvent entry as the starting value for the battery, where the additional fields are set to Nothing . Example:
pairs <- many keyValuePairs vevent = foldr f (VEvent {sequence = Nothing}) pairs where f ("SUMMARY", v) ve = ve {summary = v} f ("DSTART", v) ve = ve {dstart = read v}
... and so on. Do the same for the other components.
Edit: here is the executable code for folding:
data VEvent = VEvent { summary :: String, dstart :: String, sequenceSt :: Maybe String } deriving Show vevent pairs = foldr f (VEvent {sequenceSt = Nothing}) pairs where f ("SUMMARY", v) ve = ve {summary = v} f ("DSTART", v) ve = ve {dstart = v} f ("SEQUENCEST", v) ve = ve {sequenceSt = Just v} main = do print $ vevent [("SUMMARY", "lala"), ("DSTART", "lulu")] print $ vevent [("SUMMARY", "lala"), ("DSTART", "lulu"), ("SEQUENCEST", "lili")]
Output:
VEvent {summary = "lala", dstart = "lulu", sequenceSt = Nothing} VEvent {summary = "lala", dstart = "lulu", sequenceSt = Just "lili"}
Please note that when compiling this will result in a warning. To avoid the warning, explicitly initialize all optional undefined fields.
sepp2k
source share