[Haskell-cafe] Re: Keeping an indexed collection of values?

2009-08-21 Thread Heinrich Apfelmus
Heinrich Apfelmus wrote: Job Vranish wrote: I've been in a situation a lot lately where I need to keep a collection of values, and keep track of them by a persistent index. module Store (Key, Store, empty, add, delete, lookup) where newtype Key = Key { int :: Int } empty ::

Re: [Haskell-cafe] Re: Keeping an indexed collection of values?

2009-08-21 Thread Job Vranish
Thanks for all the input! :) My current code (unfinished) is here: http://github.com/jvranish/IndexedCollection/tree/master but I think I'll shorten the names as you suggest. (and add some strictness to availableKeys) I also added an extra phantom type parameter to the collection (and key) so

Re: [Haskell-cafe] Re: Keeping an indexed collection of values?

2009-08-21 Thread Sebastian Fischer
On Aug 21, 2009, at 5:11 PM, Job Vranish wrote: I also added an extra phantom type parameter to the collection (and key) so that I can prevent keys from being used on different collections even if they hold elements of the same type. I have the impression that this requires explicit type

Re: [Haskell-cafe] Re: Keeping an indexed collection of values?

2009-08-21 Thread Job Vranish
It only requires type annotations on your uses of empty (as that is the only way to construct a collection). The phantom type sticks to everything after that. If you don't care to add a signature then things still work just fine, you just won't be prevented from using indexes from the wrong

[Haskell-cafe] Re: Keeping an indexed collection of values?

2009-08-20 Thread Heinrich Apfelmus
Job Vranish wrote: I've been in a situation a lot lately where I need to keep a collection of values, and keep track of them by a persistent index. data IndexedCollection a = IndexedCollection { nextKey :: Int, availableKeys :: [Int], items :: IntMap a } deriving