[Haskell-cafe] Data.Ring -- Pre-announce

Daniel Fischer daniel.is.fischer at web.de
Thu Dec 31 05:54:42 EST 2009


Am Donnerstag 31 Dezember 2009 10:59:54 schrieb John Van Enk:
> Hi List,
>
> I recently needed a ring structure (circular list with bi-directional
> access) and didn't see anything obvious on Hackage. I threw something
> together fairly quickly and would like some feedback before tossing it on
> Hackage.
>
> I'd really appreciate if some one would:
>
>    1. make sure the code looks goodish (127 lines with full docs)

I think 'left' and 'right' aren't the optimal names. But I can't think of something 
clearly better either. The same applies to 'remove'.

Please, flip the arguments in 'insert'. While ring `insert` el or insert ring el may seem 
more natural (or not) and that argument order is nicer for foldl', consistency with the 
argument order of Data.List.insert, Data.Set.insert and Data.Map.insert seems far more 
important to me.

>    2. make sure my tests look saneish

Sort of. The code is so short and clear that testing it at all may hint at paranoia.
Jokes aside, prop_balance is a consequence of prop_list 
(toList . balance . fromList === toList . fromList . toList . fromList;
toList . fromList === id ==> toList . fromList . toList . fromList === id).

prop_isEmpty :: [Int] -> Bool
prop_isEmpty [] = True == (isEmpty . fromList $ []) 
prop_isEmpty l  = False == (isEmpty . fromList $ l)

prop_isEmpty [] = isEmpty . fromList $ []
prop_isEmpty l  = not . isEmpty . fromList $ l

or

prop_isEmpty l = null l == isEmpty (fromList l)


>
> If I hear nothing, I'll assume wild support and push to Hackage.
>
> Code: http://github.com/sw17ch/data-ring/blob/master/src/Data/Ring.hs
> Tests: http://github.com/sw17ch/data-ring/blob/master/tests/quickcheck.hs
> Package Root: http://github.com/sw17ch/data-ring
>
> Thanks ahead of time,
> John Van Enk

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20091231/1b454e85/attachment.html


More information about the Haskell-Cafe mailing list