[Haskell-beginners] Conciseness question

Thiago Negri evohunz at gmail.com
Sun Aug 7 15:10:04 CEST 2011


Hey Manfred.

Take a look at "Record Syntax" topic of the book "Learn you a Haskell
for great good". It looks like what you want.

http://learnyouahaskell.com/making-our-own-types-and-typeclasses#record-syntax

Thiago.

2011/8/7 Manfred Lotz <manfred.lotz at arcor.de>:
> 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
>
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list