[Haskell-beginners] Conciseness question

Manfred Lotz manfred.lotz at arcor.de
Mon Aug 8 06:02:52 CEST 2011


On Sun, 7 Aug 2011 16:27:11 -0400
David Place <d at vidplace.com> wrote:

> 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.html#v:lookup
> 

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





More information about the Beginners mailing list