sw17ch / data-clist

A purely functional ring data structure for Haskell.
Other
8 stars 9 forks source link

Foldable/Traversable instances #10

Closed noinia closed 8 years ago

noinia commented 8 years ago

Some comments:

jeremyjh commented 8 years ago

Thanks, I've merged and uploaded to Hackage.

noinia commented 8 years ago

Thanks! Although I think I've screwed up something :(. I think I should have reversed the left list of the zipper (it now traverses that part from right to left instead of left to right). The right thing to do should be:

traverse g (CList l f r) = (\f' r' l' -> CList (reverse l') f' r') 
                        <$> g f
                        <*> T.traverse g r
                        <*> T.traverse g (reverse l)

Initially, I wrote traverse as:

traverse g = fmap fromList . traverse g . rightElements 

which is cleaner, however it potentially changes the internal structure of the CList. This is not observable from the outside though. Which option do you think we should use?