[Haskell-beginners] Conciseness question
Manfred Lotz
manfred.lotz at arcor.de
Sun Aug 7 17:07:40 CEST 2011
On Sun, 7 Aug 2011 15:21:13 +0200
Ertugrul Soeylemez <es at ertes.de> wrote:
> Manfred Lotz <manfred.lotz at arcor.de> wrote:
>
> > In Lua I could do something like this:
> >
> > -- initialize empty table
> > P = {}
> >
> > P.a = "bla1"
> > P.b = "bla2"
> >
> > and so on.
> >
> > Now I can refer to each value by name, and I also can easily iterate
> > over the table P.
> >
> > How can I do something similar in Haskell. Note: I do want only
> > write each variable one time (or two times if I count the type
> > definition).
>
> I think you're not actually asking for record types at all, because
> that doesn't really fit into Haskell's type system. Rather you may
> want to have a look at maps. See the Data.Map module. Those are
> dictionaries with fast update and lookup as well as traversal
> operations.
>
Hmm, not quite sure I'm understanding why Data.Map would help.
What I want to have is something like the following without the
verboseness of it:
-- this is a minimal example.
-- Assume I would have some 15 such values.
a = "bla"
b = "bla2"
valList = [ a, b ]
Now in my program on the one hand I want to do something with all
values, thus: map doSomething valList
On the other hand I frequently want use single values in my program,
like e.g.:
let x = "suffix " ++ a
What I don't want to do is to write a definition like valList
because if I add a new value I have to remind myself not to forget to
add it to valList too.
--
Manfred
--
Manfred
More information about the Beginners
mailing list