14:54:06 <stepkut> Lemmih: 'version' is described as being the version of the type. But would it be more accurate to describe it as the version of the serialization format? For example, IxSet serializes to a list. So we can make all sorts of changes to IxSet internals (even replace it with kdtree, for example) and we can still read the data back in with out any migration..
17:16:47 <rostayob> stepkut, st3pcut: have you ever used persistent?
17:20:13 <stepkut> rostayob: no
17:20:30 <stepkut> rostayob: there was some talk of adding an MACID package to persistent though
17:21:07 <rostayob> stepkut: mhm, ok
17:21:15 <rostayob> it doesn't seem too bad...
17:21:26 <rostayob> i'm really not happy about my mongodb mapping
17:21:41 <stepkut> :-/
17:21:42 <rostayob> it's so hard to have nice storage :(
17:21:47 <stepkut> :)
17:21:52 <rostayob> in haskell at least
17:22:16 <rostayob> I mean it's not uglier than with other languages of curse
17:22:19 <rostayob> *course
17:22:23 <rostayob> but for haskell standards
17:23:02 <stepkut> :)
17:23:36 <stepkut> that's the trouble with haskell... raises your standards
17:23:40 <rostayob> are you willing to listen to my case for 3 mins and tell me what you'd do :P?
17:23:46 <stepkut> sure
17:23:51 <stepkut> I am waiting for some stuff to build
17:24:02 <rostayob> well it works already
17:24:07 <rostayob> ah your stuff :P
17:24:09 <rostayob> anyway
17:24:20 <rostayob> I have three entities: users, posts and comments
17:24:29 <stepkut> k
17:24:30 <rostayob> actually let's call posts submissions
17:24:32 <stepkut> me too
17:24:35 <rostayob> so submissions and comments
17:24:40 <stepkut> yeah
17:25:03 <rostayob> submissions and comments are really similar in the end, so I'd like to have this typeclass Post that groups the common features
17:25:33 <rostayob> I when someone votes a submission/post I update it's score
17:25:41 <stepkut> k
17:26:07 <rostayob> and I'd like to order the posts by date and score, and select all the posts by username and then order them in the same way
17:26:25 <stepkut> k
17:26:36 <rostayob> I want to have a front page with the first 20/30 submissions by date or score
17:26:46 <stepkut> k
17:27:10 <rostayob> and on the  page dedicated to a submission I want to show the comments by date or score
17:27:14 <rostayob> it's basically reddit
17:27:17 <stepkut> yep
17:27:18 <rostayob> what I've found to be tricky
17:27:39 <rostayob> is the Post typeclass while storing in the database as two different entities
17:27:42 <rostayob> anyway, how would you do it?
17:28:18 <stepkut> well.. i didn't create a type class when I did it
17:30:35 <rostayob> but in happstack-state the descending ordering would be impossible to do, right?
17:31:07 <stepkut> no, just create an index ReverseDate that has the reverse sort order
17:31:56 <rostayob> so you mean a newtype RevDate = RevDate UTCTime
17:32:26 <stepkut> yeah
17:32:44 <rostayob> where you instance Eq to be the opposite
17:32:46 <rostayob> mhm smart
17:32:55 <rostayob> same with the score right?
17:32:56 <stepkut> well, Eq will be the same, but Ord will be opposite
17:33:03 <rostayob> yes sorry, ord
17:33:10 <stepkut> same for score
17:33:31 <stepkut> or figure out how to implement toDescList for Data.Map
17:33:54 <rostayob> it'd be easy if they exported the constructors
17:34:21 <stepkut> actually, there already is a toDescList
17:34:27 <stepkut> I think that is new perhaps
17:34:35 <stepkut> so, that makes things even easier
17:34:52 <rostayob> oh right
17:34:57 <rostayob> I think it's new as well
17:35:14 <rostayob> cool!
17:35:21 <rostayob> the only slightly annoying thing
17:35:29 <rostayob> is that I can't keep the comments ordered
17:35:45 <rostayob> If I have an ParentID index or something like that
17:35:49 <stepkut> toDescList added in containers 0.3 -- which came out in 2009
17:36:09 <stepkut> threaded comments are a big pain
17:36:09 <rostayob> oh ok, then I'm just stupid
17:36:29 <rostayob> stepkut: they're not bad, I mean the best solution imho is to record the parent
17:37:02 <stepkut> well... I consider toDescList to be pretty new.. I've ben using Data.Map since 2002 :p
17:37:19 <rostayob> stepkut: I've used haskell seriously since last september so :P
17:37:40 <rostayob> too much stuff to learn ehe
17:40:16 <stepkut> so, for IxSet we actually need to implement, toAscList :: (Ord k, Typeable k) => k -> IxSet a -> [a] and toDescList :: (Ord k, Typeable k) => k -> IxSet a -> [a]. But that should be trivial
17:40:59 <stepkut> mostly..
17:42:26 <stepkut> there is an issue with duplicates
17:42:40 <rostayob> what issue?
17:43:44 <stepkut> if you have, Foo String String, And you insert, Foo "bar" "baz", then your Map will contain, Map.fromList [ ("bar", Foo "bar" "baz"), ("baz", Foo "bar" "baz") ]
17:43:49 <rostayob> oh, actually, Set is the one that doesn't have toDescList
17:44:06 <stepkut> so.. you need to nub the results of Map.toAscList / Map.toDescList
17:48:47 <stepkut> or we could just provide groupByAsc and groupByDesc and let the user determine how they want to handle duplicate values
17:49:16 <rostayob> stepkut: can't you just get the list from the Set?
17:49:23 <rostayob> so that you won't have duplicates
17:49:55 <stepkut> which Set?
17:49:56 <rostayob> I mean from one of the Sets of the ixSet
17:50:37 <rostayob> I remember IxSet being a collection of Sets, right?
17:50:38 <stepkut> well, each index of an IxSet is a Map key (Set values)
17:50:43 <rostayob> yeah
17:50:47 <stepkut> but you want things ordered by the key
17:50:53 <rostayob> ah right
17:51:05 <stepkut> the Sets are just sets of values with the same key
17:51:11 <rostayob> oh ok
17:51:14 <stepkut> but in my example, I have two different keys that map to the same value
17:51:29 <rostayob> so how can you define fromDescList easily?
17:51:43 <stepkut> groupByDesc is easy
17:52:55 <stepkut> look at the definition for groupBy, http://patch-tag.com/r/mae/happstack/snapshot/current/content/pretty/happstack-ixset/src/Happstack/Data/IxSet.hs
17:53:14 <stepkut> just change, Map.toList to Map.toAscList or Map.toDescList
17:53:21 <stepkut> that gives you groupByAsc and groupByDesc
17:54:03 <stepkut> toAscList and toDescList are 'tricky' because you have to decide what the correct behavior is
17:54:41 <rostayob> no but apart from that, each Set in the IxSet is orderd against the data type ordering right?
17:56:21 <stepkut> if you call Set.toAscList then values with the same key will be sorted by the Ord instance for the data type
17:56:41 <stepkut> (currently Set.toList just calls Set.toAscList)
17:57:24 <stepkut> regarding IxSet.toAscList 'IxSet.toAscList (Proxy :: Proxy String) (IxSet.fromList [(Foo "bar" "baz")])' return [Foo "bar" "baz"] or should it return, [Foo "bar" "baz", Foo "bar" "baz"]
17:57:51 <rostayob> ok, while what I want is to order it after some field in the data type. how do you do that efficiently?
17:58:33 <stepkut> groupByAsc :: (Typeable k,Typeable t) =>  IxSet t -> [(k, [t])]
17:58:49 <stepkut> the 'k' (keys) in that list will be sorted in Asc order
17:58:56 <stepkut> or you can use groupByDesc
18:00:46 <stepkut> so if you have [(UTCTime, [Post])], then you will get a list of posts sorted by time. If two posts were made at the exact same time then they will be sorted by the Ord instance for Post
18:01:03 <rostayob> yes but you won't get the sorting for free, will you?
18:01:33 <stepkut> depends on what you mean for free. You pay the price when you insert the data
18:02:23 <stepkut> for a query it just calls, Map.toAscList with is O(n) (same as Map.toList)
18:02:36 <rostayob> yeah exactly, it's O(n)
18:02:43 <stepkut> you can't do better than O(n)
18:02:43 <rostayob> you don't have a set in which the values are already ordered right?
18:03:00 <stepkut> a Map is a set in which the values are already ordered
18:03:36 <rostayob> stepkut: no but I don't understand where do you store the objects ordered after the various keys
18:03:44 <stepkut> if you have a container with 'n' elements in to (such as a Map, List, Set, etc) then converting to another container can not possible be faster than O(n), right ?
18:03:57 <rostayob> you mean O(n) as in traversing the tree, but no comparison?
18:04:00 <rostayob> yes right
18:04:12 <rostayob> I mean you have to traverse the whole tree
18:04:27 <rostayob> but I don't understand where do you get the ordering after some index...
18:04:28 <stepkut> yes, Map is just a balanced tree, indexed on the key. So to get the sorted values you just traverse
18:05:11 <rostayob> stepkut: yes but where is the Map indexed after they key that I want? I mean in an IxSet you've got a map from the keys to sets of stuff
18:05:29 <rostayob> but the elements in the sets are not ordered after that key
18:05:42 <stepkut> the elements in each set all have the same key
18:06:19 <rostayob> ohhh right so you don't need to order those
18:06:23 <stepkut> yep
18:06:37 <rostayob> but you still need to prune the duplicates
18:06:49 <stepkut> that depends on your application
18:08:46 <stepkut> let's say that your key is the name of an Actor and the value is a Film.
18:09:37 <stepkut> if you want to create an alphabetical list of actors and clicking on them shows the film the are in.. then you don't want to purge duplicate Films
18:10:01 <stepkut> that is where groupByAsc is useful..
18:10:15 <stepkut> for toAscList is less clear if purging duplicates is the correct thing or not
18:11:08 <stepkut> the most flexible thing is for toAscList to not purge duplicates, and let the user call nub if they need it
18:11:14 <stepkut> that also keys toAscList faster
18:12:06 <rostayob> mhm yeah maybe you're right
18:12:40 <stepkut> if you do purge duplicates .. which do you keep? the first or the last? and why?
18:12:56 <stepkut> hard to say with out better use cases
18:13:18 <rostayob> yeah I see the issues, but let's say that I'm ordering by date/score. apart from the fact that it's highly unlikely to have duplicates
18:13:29 <rostayob> but if I do I definitely want to purge them, I don't care which ones
18:13:36 <stepkut> in your examples, the posted date and score are values that only appear once in a POST so you won't have duplicates
18:14:00 <rostayob> well you can have score duplicates
18:14:05 <rostayob> a score is just a Float
18:14:13 <stepkut> yes, but the score is a key
18:14:32 <stepkut> the same post will not have multiple scores will it?
18:14:33 <rostayob> right
18:14:45 <rostayob> you are right you can't have duplicates in that case
18:15:02 <stepkut> yeah, you only get duplicates when the key can appear multiple times in a single value
18:15:10 <stepkut> such as a list of Actors in a movie
18:15:33 <rostayob> do you think the list things could be implemented quickly?
18:15:56 <stepkut> yep
18:16:01 <rostayob> isn't it just toDescList + toList?
18:16:07 <rostayob> I mean toList on the Set
18:16:11 <stepkut> yep
18:16:11 <rostayob> the inner Sets
18:16:27 <stepkut> I already implemented groupByAsc and groupByDesc. Now I am testing
18:16:37 <stepkut> and adding haddock documentation
18:16:51 <rostayob> cool cool
18:16:57 <rostayob> got to go now, I'll check the repository
18:17:04 <rostayob> thanks for the help
18:18:26 <stepkut> k
19:46:36 <rostayob> stepkut, st3pcut: i'm baaaak
19:46:38 <rostayob> *back :P
19:46:42 <st3pcut> sweet
19:46:44 <st3pcut> I made lunch
19:46:49 <st3pcut> so I have not commited the patches yet
19:46:51 <st3pcut> soon
19:46:57 <rostayob> anyway, let me know when you put those functions on hackage, and I'll try to switch to happstack-state/ixset
19:47:00 <rostayob> ok
19:47:09 <rostayob> ok I think we're on different time zones ehee
19:47:47 <st3pcut> probablp
19:47:53 <st3pcut> though it is 2:48pm here
19:47:59 <st3pcut> so not exactly a normal lunch time either
19:48:03 <rostayob> 8.48 here
19:48:11 <rostayob> and i was on a different timezone yesterday
19:48:21 <rostayob> but my sleep pattern quite bad
19:48:29 <rostayob> i mean i don't have one
19:49:48 <rostayob> mah
20:56:00 <rostayob> st3pcut, stepkut: would you suggest to use acid-state directly now?
21:07:35 <stepkut> rostayob: instead of indirectly?
21:07:57 <rostayob> stepkut: instead of using happstack-state and then switching (:
21:08:36 <stepkut> I've started to
21:08:47 <stepkut> gotta find the bugs somehow :p
21:36:31 <stepkut> ok, added toAscList, toDescList, groupAscBy and groupDescBy
21:45:23 <rostayob> cool, it's the 6.0.1 on hackage rightt?
21:47:52 <rostayob> yes it is
21:47:53 <rostayob> thanks
21:48:29 <rostayob> how would you solve the threaded comments problem?
21:49:17 <rostayob> I don't think that having a parentId is too bad
21:59:42 <stepkut> in addition to parent id you also need a way to order the children
21:59:47 <stepkut> possible by date
22:00:40 <rostayob> stepkut: you just sort them
22:44:16 <stepkut> rostayob: right, you just need a key to sort on.. such as date
22:44:40 <rostayob> stepkut: yes, but what I meant is that sorting them directly is not a big thing if you have 300 comments
22:44:50 <rostayob> the problem is more that you'd have to do a lot of queries
22:45:18 <stepkut> rostayob: with MCAID you can just do, import Data.Tree ; type Comments = Tree Comment .. but that turns out to not work well in practice because it makes it hard to permalink to a specific comment and things like that
22:45:32 <rostayob> stepkut: exactly
22:45:57 <rostayob> it makes really hard to do anything on the comment really... voting it, editing it...
22:46:06 <stepkut> yep
22:46:22 <rostayob> so there is no better solution you have found?
22:48:04 <stepkut> not really
22:51:44 <rostayob> ok, that's reassuring (:
22:54:28 <rostayob> stepkut: also, I didn't understand if it's better to start with acid-state now or to go with happstack-state
23:16:02 <stepkut> rostayob: i would start with acid-state