[Haskell-beginners] Conciseness question

Manfred Lotz manfred.lotz at arcor.de
Sun Aug 7 13:25:48 CEST 2011


Hi all,
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 thought about:

data P = P {
     a :: String,
     b :: String 
}

Then I have one definition

pval = P {
   a = "bla1",
   b = "bla2"
}

Now I could refer to each val easily, e.g. a pval. However, I don't see
that I could iterate over the members of pval.


It there a way to do what I want without defining a list like this?
pls p = [ (a p), (b p)]

Perhaps a comletely different way?



-- 
Manfred





More information about the Beginners mailing list