[Haskell-cafe] Simple Table Update

Ryan Ingram ryani.spam at gmail.com
Wed Oct 8 13:03:36 EDT 2008


Prelude> :t Data.List.mapAccumL
Data.List.mapAccumL :: (acc -> x -> (acc, y)) -> acc -> [x] -> (acc, [y])

I'm sure you can fill in the details :)

  -- ryan

2008/10/8 Paul Keir <pkeir at dcs.gla.ac.uk>:
> 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
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>


More information about the Haskell-Cafe mailing list