[Haskell-cafe] Simple Table Update

Paul Keir pkeir at dcs.gla.ac.uk
Wed Oct 8 11:25:01 EDT 2008


Hi,

I'd like to create a new list based on an original list, using information from a second (symbol) list. That second list should be updated as each element in the new list is added. I've been using map a lot, but that's not an option here, and I'm having trouble obtaining a good recursive structure for my function.

The minimal "fixpus" function below shows the problem. I have "sts" on both sides of the ":" list construct, but I'd like the second "sts" to be a version modified by the where (singular) function, "fixpu".

fixpus :: [ProgUnit] -> [ProgUnitSymbolTable] -> [ProgUnit]
fixpus []       _  = []
fixpus (pu:pus) sts = fixpu pu sts : fixpus pus sts

  where fixpu pu sts = pu

(Below) I tried making "fixpu" return a tuple, and then use "fst", "snd" and "let", but I think it looks strange. I know it's quite basic, but I'd like a strong foundation for what's likely to become a medium-scale project. Can anyone offer advice?

fixpus :: [ProgUnit] -> [ProgUnitSymbolTable] -> [ProgUnit]
fixpus []       _  = []
fixpus (pu:pus) sts = let a = (fixpu pu sts) in fst a : fixpus pus (snd a)

  where fixpu pu sts = (pu,sts ++ [("",[])])

Regards,
Paul

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081008/3719b9a9/attachment.htm


More information about the Haskell-Cafe mailing list