
On Sun, 7 Aug 2011 16:27:11 -0400
David Place
On Aug 7, 2011, at 3:55 PM, Manfred Lotz wrote:
import Data.Map (Map, (!), lookup)
lookup ConfigAppDir myDirs myDirs ! ConfigAppDir
This is the solution I like. I have to accept that here I cannot reach the conciseness of which might be due to Haskell being strongly typed.
In your original note, you mentioned that you have a small number of entries in your list of directories. If so, you might find that association lists work just fine for you without needing to import Data.Map.
http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.htm...
Yes, this is true. Assoc lists would do just fine. What I found is that there is no real concise way of defining something like this in Haskell. The shortest definition I found is this: ([cAppDir, dAppDir, oAppDir],dirlist) = (l,l) where l = [ "app/config", "app/data", "app/other"] which is ok. However, here I must be careful (when having 15 directories or so) to keep the sequence of variable names in line with the sequence of directories in l. Additionally, if I have a different number of directories in l than I have variable names in the beginning of the definition list (cAppDir aso) I would only notice at runtime when accessing any of those variables. That is why a data type and then something like an assoc list is safer to use (but more verbose). -- Manfred