--- Log opened Fri Feb 13 00:00:10 2009
01:43 < mae_> helllooo
01:45 < mae_> Saizan: how is this business with dsrogers going?
01:46 < mae_> Saizan: i'm kind of curious to know when a good stopping point would be if i wanted to release 0.2 in the first week of march
01:54 < gour> morning
01:55  * gour would like to use haskell for web development instead of going via python/django route
01:57 < gour> ..so no matter if one would use happstack or e.g. something lighter (turbinado) i wonder how/if it would be possible to use reST markup in such CMS? atm, i'm aware about pandoc, but it parses only subset of reST...
01:57 < gour> and, btw, any eta for 1.0? :-D
02:00 < Axman6> well, 0.1 was just released...
02:24 < paulvisschers> Is there a way to use something of type Query inside an Update?
05:46 < koeien> paulvisschers: runQuery
06:04 < paulvisschers> koeien: thanks
06:05 < paulvisschers> Although I fixed it myself in another way
06:05 < paulvisschers> Update is an instance of MonadReader, so making the types more general works too
06:06 < paulvisschers> This may be nicer though
10:04 < oshyshko> Where I can read about writing JSON-RPC web-services with HAppS?
10:09 < oshyshko> ...may be some test-case from HAppS sources or code snippet will be enough...
10:15 < stepcut> oshyshko: at the most basic level, writing a JSON web-service is almost exactly like writing a normally html application
10:15 < stepcut> except you return some JSON objects instead of html pages
10:17 < stepcut> you can use a library like this one for the json stuff, http://hackage.haskell.org/cgi-bin/hackage-scripts/package/json
10:24 < oshyshko> Is it able to convert regular data like data User = User { name :: String, coins :: Int } to JSON?
10:27 < oshyshko> ... e.g. I write a function: listUsers :: [User], register it to some URI - so HAppS invokes it and converts result value ([User]) to JSON and sends as response.
10:32 < stepcut> there is a library, RJson which attempts to automatically convert regular data types to JSON, but I am not thrilled by it
10:33 < stepcut> I have a demo of using it here, but it is mixed in with a demo of using happ-hsp-template, which does not work anymore and is being replaced
10:33 < stepcut> http://nhlab.blogspot.com/2008/07/html-templating-in-happs-using-hsp.html
10:34 < stepcut> hrm, that article is really not going to be useful
10:36 < stepcut> basically, you would do something like [dir "json" [ dir "listUsers" [ method GET $ ok . toResponse . toJson =<< listUsers ]]]
10:37 < stepcut> the problem with RJson is that it does not know how to automatically make JSON instances for algebraic data-types with multiple constructors. But that is a silent runtime error.
10:38 < stepcut> if you JSON types are already named records or simple types, then it works
10:38 < stepcut> otherwise you have to create JSON instances by hand
10:38 < Saizan> there's no standard way to represent sums in json?
10:40 < stepcut> Saizan: dunno. it's certainly not as obvious as mapping haskell records <-> javascript 'records'.
10:41 < Saizan> i'd guess something like tagged unions in C
10:42 < stepcut> javascripts types are: float, array(?), bool, string, function, and objects (which are basically hash tables/structs)
10:43 < stepcut> oh, and null I guess
10:43 < oshyshko> wow. thanks!
10:46 < mae_> stepcut, I am delving into the whole hsp/hstringtemplate thing now, I am debating whether to initially support compiled hsp vs eval
10:46  * stepcut has no idea how javascript programs implement, data Either a b = Left a | Right b
10:46 < mae_> hstringtemplate only has eval mode as far as i know
10:46 < mae_> bbl
10:46 < stepcut> ok
10:46 < Saizan> yeah, so data Foo = A x y | B w z => A x y = { a = [x,y]}, B w z = { b = [w,z]}, considering reflection etc..
10:47 < Saizan> that's what i'd imagine, i guess
10:48 < stepcut> so to deserialized it, you check and see which member variable of the json object exists, a vs b ?
10:48 < Saizan> yes
10:49 < stepcut> I think in my code I pass in an extra string indicated what 'type' it is
10:49 < stepcut> { type = "A", value = [x,y] } vs { type = "B", value = [w,z] }
10:50 < stepcut> { constr = "A", args = [x,y] } might be a better choice of names
10:51 < stepcut> then in the javascript code you can do, switch j.type of { case "A" : foo; break; case "B" : bar; break; }
10:52 < Saizan> yeah, probably nicer
10:52 < stepcut> where foo and bar do something with j.args
10:52 < stepcut> but, that is just my own standard.
10:52 < Saizan> and with named fields args is an object instead of an array?
10:54 < stepcut> I just stick the named fields right in the same object
10:54 < stepcut> { constr="A", x = x, y = y }
10:55 < stepcut> in the limited case where I use these my JSON instances are hand written, so I have not done this in a programmatic way
10:57 < stepcut> its for representing simple algebra expresions like, 3 * c, becomes, { type="binOp", op="*", x=3, y='c' }
10:58 < stepcut> and, 3 * (c + 4), becomes, { type="binOp", op="*", x=3, y={type="binOp" op="+" x="c" y=4 }}, or something like that
10:58 < dsrogers> *yawn*
10:59 < stepcut> I think I have constructors for lit and var actually
10:59 < stepcut> json's only redeeming value is that javascript can call 'eval' to turn it into an object :-(
11:04 < Saizan> dsrogers: the last WebT looks good, for applyFilter you probably don't want 'b' to be a parameter of the class
11:04 < dsrogers> ok
11:04 < dsrogers> just f then?
11:04 < Saizan> and you shouldn't require the result to be a functor
11:04 < dsrogers> ok
11:05 < dsrogers> ah I see.
11:05 < Saizan> can you also include an implementation of the old escape with that?
11:05 < dsrogers> I was trying to make everything a parameter of the class instead of just leaving some things polymorphic to the function...
11:07 < dsrogers> old escape is applyFilter id $ finishWith r
11:08 < dsrogers> err, no.
11:08 < dsrogers> I think that's escape'
11:08 < dsrogers> so, m >>= applyFilter id . finishWith
11:09 < dsrogers> that's escape
11:09 < dsrogers> err...
11:09 < dsrogers> ok.  It's tool early in the moring.
11:10 < dsrogers> did escape avoid applying filters?
11:10 < dsrogers> I think it did...
11:10 < Saizan> yes
11:10 < Saizan> well, it applied the filters of the action passed to it
11:10 < Saizan> but not any filter before or after
11:11 < dsrogers>  setFilter id >> m >>= finishWith r
11:11 < dsrogers> that should do it.
11:12 < dsrogers> m's filter is preserved
11:13 < dsrogers> only drop the r...
11:13 < Saizan> ok
11:15 < Saizan> so runWebT :: ToMessage r => WebT m r -> m (Maybe Response), where the resulting filter is applied to both the Left and Right branches?
11:16 < dsrogers> yes
11:28 < dsrogers> something close to msum [applyFilters toResponse m, return Nothing]
11:29 < dsrogers> with some glue to unpack the monad stack.
11:32 < dsrogers> hmm.
11:34 < dsrogers> anyways...assuming noone points out a glaringly obvious flaw, I'll insert some useful MTL instances, and create a patch...
11:34 < dsrogers> um... this weekend, probably
11:34 < dsrogers> off to work!
11:35 < dsrogers> thanks for the help, Saizan
12:00 < paulvisschers_> I heard from someone that happs-state only stores the input to methods, and not the output, since that can be recalculated from the input
12:00 < paulvisschers_> but when I do :i UpdateEvent in ghci, it stats that the ouput must be an instance of Serialize
12:01 < paulvisschers_> so what's up with that?
12:07 < stepcut> paulvisschers_: I think it is used by spread
12:07 < stepcut> for the multimaster stuff
12:08 < paulvisschers_> hmm ok
12:08 < paulvisschers_> Then a follow-up question: is there a good way to make an instance of Serialize for Html?
12:10 < stepcut> paulvisschers_: I don't see a way
12:11 < paulvisschers_> instance Serialize Html where
12:11 < paulvisschers_>   getCopy = contain (H.primHtml <$> safeGet)
12:11 < paulvisschers_>   putCopy = contain . safePut . H.showHtml
12:11 < paulvisschers_> I have this at the moment, but I think this might break
12:11 < stepcut> yeah
12:12 < paulvisschers_> yeah on the breaking?
12:13 < stepcut> maybe you don't want to be returning html from your update function anyway? what if you want to switch to a different html library later?
12:15 < stepcut> the original happs authors were big on 'separation of concerns', and would probably recommend that your update function returns a type that contains the information you need, and some other code worries about turning it into html, or whatever is needed
12:15 < stepcut> knowing nothing about what you are doing, I can't say if that is appropriate in your case
12:18 < stepcut> one use model was to have your happs application only deal with types that had the information needed, but not 'presentation layer' stuff. Your types would then be automatically turned into XML, and you would use xslt to turn that data into html
12:18 < koeien> agreed
12:19 < stepcut> unfortuantely, xslt is not very good. But you can do the same thing all in haskell
12:19 < stepcut> simpleHTTP (transformToHtml (impl :: [ServerPartT IO ResponseData]))
12:20 < stepcut> in theory, that might make it easy to provide a REST/JSON api that matches the html version of the site?
12:22 < stepcut> if you serialize an 3rd party data type, like Html, and then the upstream authors change the internals of the type, you might run into migration issues
12:23 < stepcut> though, in this case, Html is not an instance of Typeable and Data, nor does it export any constructors
13:04 < paulvisschers_> stepcut: That might be a good idea
13:04 < paulvisschers_> The thing is that I have a form library, that validates the input
13:04 < paulvisschers_> and generates a piece of html if something is wrong, including error messages to the user
13:05 < paulvisschers_> but since I need the validation of the data and the updating of the state to be atomic, I had to put it inside of a method
13:06 < paulvisschers_> which is the reason I sometimes return html
13:06 < paulvisschers_> I would really like another way of doing this though
13:09 < stepcut> paulvisschers_: does that mean uses of your form library have to use the same html library as you?
13:09 < paulvisschers_> yup
13:09 < paulvisschers_> as it generates the html for you
13:11 < paulvisschers_> I could generalize the combinators and such of course, but a lot of it is very presentation specific
13:11 < stepcut> paulvisschers_: in the formlets library, the core code does not specify any particular library. It then provides an additional XHtml helper library. But if you want to use another library, you can easily write your own html wrappers. That is kind of nice.
13:12 < paulvisschers_> Yeah it wouldn't be hard to do the same here
13:12 < paulvisschers_> But I'm building the lib by my own needs atm
13:14 < paulvisschers_> But the style that my lib and formlets use aren't really very compatible with happs it seems
13:14 < stepcut> I have not had issues using formlets with happs...
13:14 < paulvisschers_> Since with both the forms have an embedded monad to perform validation with
13:15 < paulvisschers_> So how do you do it?
13:16 < paulvisschers_> It seems that the straightforward way isn't good enough, since validation would preceed updating in a non-atomic way
13:16 < paulvisschers_> so by the time you do the update, the data might be invalid
13:16 < stepcut> ah
13:17 < stepcut> I don't think I have had to deal with that issue yet
13:20 < paulvisschers_> Well as long as your validation is independent of the state, there is no problem
13:20 < paulvisschers_> but as soon as it does, I don't see it working at all
13:21 < paulvisschers_> does -> isn't
13:23 < stepcut> i look into it later
23:09 < dsrogers> greetings
--- Log closed Sat Feb 14 00:00:13 2009