Hello! You have several options. First, consider that when you lookup (see Prelude.find) a field in the alist, you're going to stop as soon as you find the first match. So, as long as you're appending new fields to the front of list, then you'll be ok (it will be correct, but not efficient).
Greetings,I'm struggling to find a way to define an "Alist" once, and then simply add-in "Fields" to it incrementally.. without having to keep using new identifiers/variables to hold the result of each "addin" expression.I understand that pure Functional Programming doesn't use destructive state changes, but I'm wondering if there is a way to make this happen using Monads, for example (which I have a cursory understanding of..)Instead of doing this:type Root = Stringtype Oct = Integertype Mode = Integerdata Field = Root Root | Oct Oct | Mode Mode deriving (Show)type Alist = [Field]addin :: Alist -> Field -> Alistaddin p f = f:pp0 :: Alistp0 = []p1 = addin p0 (Root "c")p2 = addin p1 (Oct 4)p3 = addin p2 (Mode 3)p4 = addin p3 (Oct 3)-- ... p42, etcFor 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..I'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't been added yet.Many Thanks,Tom Jordan
_______________________________________________
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell