Hello, all!

I need to create objects like this

data Object = MyObject { param1, param2, param3 :: String }

from the input file

param_1_param1=value11
param_2_param1=value21
param_2_param2=value22
param_1_param3=value13
param_2_param3=value23
param_1_param2=value12

so general pattern of recognizing parameter name and value is

param_{id}_{property name}={property value}

so I need to create function

> parseDataFile :: [String] -> [Object]

For now I can think on splitting the task into 2 functions

> groupSameObjectParameters :: [String] -> [[String]]

which will group the lines with same id into a list, and then apply function

> createObject :: [String] -> Object

so overall solution will be

> parseDataFile :: [String] -> [Object]
> parseDataFile = map createObject . groupSameObjectParameters

however I have no neat idea about how to create instance of MyObject - I need
to supply all of parameters to the constructor at once.

Also I don't like the idea of rearranging list first and then create objects
from another list, because the list can be relatively large.

In imperative programming with mutable objects I would create an array, then
for each line get the id and try to find if there is the object in the array
at 'id' index. If no - create one. Then set appropriate property from value.

Is it possible to do something similar in Haskell?

Thank you in advance!

-- 
Eugene N Dzhurinsky

Attachment: pgpi8YKuw3492.pgp
Description: PGP signature

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to