Pergunta

i have the following situation. I get week datas from probes. Datas are collected in several xml files (inline in the code below). I need to concat these in one file. Though i aggregate them in one record that can further be translated into a single file.

The result record i try to catch is the following :

    [YS {ser = "MSG"
        , ori =[YO {site = "Bordeaux" , perfM = ["0","0"]  }
               ,YO {site = "Paris"    , perfM = ["1","1"]}]}
    ,YS {ser = "OTP"
        , ori =[YO {site = "Marseilles" , perfM = ["20","20"]}
               ,YO {site = "Lyon"       , perfM = ["21","21"]}]}
    ]

as you can see perfM collects all datas.

But the following code give me that.

    [YS {ser = "MSG"
        , ori = [YO {site = "Bordeaux", perfM = ["0"]}
                ,YO {site = "Paris", perfM =["1"]}
                ,YO {site = "Bordeaux", perfM = ["0","0"]}
                ,YO {site = "Paris", perfM = ["1","1"]}]}
    ,YS {ser = "OTP"
        , ori = [YO {site = "Marseilles"
                , perfM = ["20"]}
                ,YO {site = "Lyon", perfM =["21"]}
                ,YO {site = "Marseilles", perfM = ["20","20"]}
                ,YO {site = "Lyon", perfM = ["21","21"]}]}
    ]

This is really unclear to me what's going on here and where should i need to look at. I think it's in the getYearOri and the addOri functions but so far all my attemps lamentably failed.

if anyone could give me a clue on the code to be changed.

Foi útil?

Solução

I think i have found my error. The addScen function is not correct and should be change to

        addScen :: YScen -> [YScen] -> YScen
        addScen sc [] = sc
        addScen sc (x:xs) 
                    | ser sc == ser x
                                = YS {ser=ser sc
                                     ,ori=(ori sc) }  
                                    -- ,ori=(ori x) ++ (ori sc) <--- Error 
                    | otherwise = addScen sc xs

To find this i had to read documentation about debbuging haskell and the most usefull comment where " write small functions and test them. then compose. "

I broke my code into small parts and test every part of it. But this is tedious compared to other languages where debbugger are friendlier than ghc's one.

Sorry for the annoyance. i post my solution in case some may be interested in.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top