<div>Greetings,</div><div><br></div><div>I&#39;m struggling to find a way to define an &quot;Alist&quot; once, and then simply add-in &quot;Fields&quot; to it incrementally.. without having to keep using new identifiers/variables to hold the result of each &quot;addin&quot; expression.</div>
<div>I understand that pure Functional Programming doesn&#39;t use destructive state changes, but I&#39;m wondering if there is a way to make this happen using Monads, for example  (which I have a cursory understanding of..)</div>
<div><br></div><div>Instead of doing this:</div><div><br></div><div><div>type Root = String</div><div>type Oct  = Integer</div><div>type Mode = Integer</div><div><br></div><div>data Field = Root Root | Oct Oct | Mode Mode deriving (Show)</div>
<div><br></div><div>type Alist = [Field]</div><div><br></div><div>addin :: Alist -&gt; Field -&gt; Alist</div><div>addin p f = f:p</div><div><br></div><div>p0 :: Alist</div><div>p0 = []</div><div>p1 = addin p0 (Root &quot;c&quot;)</div>
<div>p2 = addin p1 (Oct 4)</div><div>p3 = addin p2 (Mode 3)</div><div>p4 = addin p3 (Oct 3)</div><div>-- ... p42, etc</div></div><div><br></div><div><br></div><div>For the Alist version, when adding-in a Field with the same constructor-name as one that has already been added-in, it adds-in a brand new entry (with a repeated key-name (in the form of another constructor) and its associated value), as a normal association list does..</div>
<div><br></div><div>I&#39;m also looking to define a Property-List version, where a Field-name/constructor can update a previous value (if the Field has already been added), or add-in a new entry if the Field hasn&#39;t been added yet.</div>
<div><br></div><div><br></div><div>Many Thanks,</div><div><br></div><div>Tom Jordan</div>