Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Ok, so between <code>BEGIN:VEVENT</code> and <code>END:VEVENT</code>, you have many key value pairs. So write a rule <code>keyValuePair</code> that returns <code>(key, value)</code>. Now inside the rule for <code>VEVENT</code> you do <code>many KeyValuePair</code> to get a list of pairs. Once you've done that you use a fold to populate a VEVENT record with the given values. In the function you give to fold, you use pattern matching to find out in which field to store the value. As the starting value for the accumulator you use a VEvent record where the optional fields are set to <code>Nothing</code>. Example:</p> <pre><code>pairs &lt;- 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} </code></pre> <p>...and so on. Do the same for the other components.</p> <p>Edit: Here's some runnable example code for the fold:</p> <pre><code>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")] </code></pre> <p>Output:</p> <pre><code>VEvent {summary = "lala", dstart = "lulu", sequenceSt = Nothing} VEvent {summary = "lala", dstart = "lulu", sequenceSt = Just "lili"} </code></pre> <p>Note that this will produce a warning when compiled. To avoid the warning, initialize all non-optional fields to <code>undefined</code> explicitly.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload