Re: [Haskell-cafe] Where to start about writing web/HTTP apps ?

2005-09-12 Thread S. Alexander Jacobson

a better example

http://www.intertwingly.net/blog/2005/07/22/REST-vs-API


On Mon, 12 Sep 2005, S. Alexander Jacobson wrote:


On Mon, 12 Sep 2005, Joel Reymont wrote:

Why not XML-RPC?


REST is more appropriate for the applications on which I work.

See http://webservices.xml.com/pub/a/ws/2002/02/20/rest.html

-Alex-

__
S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com




On Sep 12, 2005, at 9:54 PM, S. Alexander Jacobson wrote:


6. define how busines logic maps to URLs

  ...
  a POST _ ["u"] = doXML addUser
  a GET "myapp.com" ("s":path) = fileServe mimeTypes "static" path

  myApp appCtx = let ?style=XSL "/s/style.xsl" in simpleHTTP a appCtx







__
S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Where to start about writing web/HTTP apps ?

2005-09-12 Thread S. Alexander Jacobson

On Mon, 12 Sep 2005, Joel Reymont wrote:

Why not XML-RPC?


REST is more appropriate for the applications on which I work.

See http://webservices.xml.com/pub/a/ws/2002/02/20/rest.html

-Alex-

__
S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com




On Sep 12, 2005, at 9:54 PM, S. Alexander Jacobson wrote:


6. define how busines logic maps to URLs

  ...
  a POST _ ["u"] = doXML addUser
  a GET "myapp.com" ("s":path) = fileServe mimeTypes "static" path

  myApp appCtx = let ?style=XSL "/s/style.xsl" in simpleHTTP a appCtx




___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Where to start about writing web/HTTP apps ?

2005-09-12 Thread Joel Reymont

Why not XML-RPC?

On Sep 12, 2005, at 9:54 PM, S. Alexander Jacobson wrote:


6. define how busines logic maps to URLs

  ...
  a POST _ ["u"] = doXML addUser
  a GET "myapp.com" ("s":path) = fileServe mimeTypes "static" path

  myApp appCtx = let ?style=XSL "/s/style.xsl" in simpleHTTP a appCtx


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Where to start about writing web/HTTP apps ?

2005-09-12 Thread S. Alexander Jacobson
I will be launching (beta) a new commercial chat site written using 
Haskell and AJAX in the next month.  The server is written on top of 
the HAppS library I made available at http://HappS.org.


My general pattern for writing an application in this framework is 
write the server based on a wire-level spec where the server takes in 
XML/x-www-form-encoded/multipart-form-data and returns XML.  Client 
side XSLT stylesheets then handle conversion of the XML to HTML.  Here 
are the details if you are interested:


1. Write a web service spec as a reference for both client and server 
development.  I use an informal language for this that relies on a 
mix of the reader understanding HTTP semantics and RelaxNG XML specs.


  POST /login ? {username {text},password{text},url{URL},captcha(text}}
  200 session {attribute userId{text},attribute href {rel-URL}}

  Some text here describing other details that don't fit into the
  syntactic model described above.  Server is assumed to handle any of
  application/x-www-form-urlencoded, multipart/form-data, or
  application/xml.  Client is assumed to receive application/xml.
  Browser is assumed to handle XSL stylesheet PIs.  (All conversion
  from XML to HTML is handled client side or on proxy using XSLT
  template)

2. Define Server State and state model

  data State = State {users::UserData}
  ...definition of user data...

  startState = State mzero
  addStateUser state user = 

3. Define serialization for server state

  instance Show State where ...
  instance Read State where ---

4. Define exposed business logic

  addUser appCtx regInfo = if regGood then actionOk newState [] newUserInfo
   else qOk badRegInfo
  ...

5. define required wire formats for types

  --convert internal data type to XML
  instance ToElement NewUserInfo where
 toElement n = ...

  --convert posted data to internal data type
  instance FromMessage RegInfo where
 fromMessage msg = ...

6. define how busines logic maps to URLs

  ...
  a POST _ ["u"] = doXML addUser
  a GET "myapp.com" ("s":path) = fileServe mimeTypes "static" path

  myApp appCtx = let ?style=XSL "/s/style.xsl" in simpleHTTP a appCtx


7. define the app to execute

  run  path host = do
   app <- startApp $ simpleConfig path startState confro
   serve host app
   return ()

  main = run "appdir" "localhost:80"

8. put client side stuff (including style.xsl) in the "static" directory

9. install searchpath (see http://searchpath.org)

10 run it!

  $ searchPath ghc -o MyApp --internet http://searchpath.org/default.map 
src/MyApp.hs
  $ MyApp

HAppS and the chat applications are still works in progress, but I 
have this running successfully internally already!


-Alex-
__
S. Alexander Jacobson tel:917-770-6565 http://alexjacobson.com


On Mon, 12 Sep 2005, Sam Mason wrote:


gary ng wrote:

I want to write apps for WEB and have briefly read
WASH.


I'm thinking of doing the same.  The approach taken by WASH seems very
cool and I'd love to use it.  I've only started looking at it, but
WASH seems to require that JavaScript be enabled on the user's web
browser, even for the simplest forms.  e.g. from the authors web page:

 http://nakalele.informatik.uni-freiburg.de/cgi/WASH/Counter.cgi

Also, the error checking doesn't seem to work as I'd expect:  if
you submit a page without a required field it will complain the
first time, then make something up the second time around -- even
if you haven't entered anything in the field.


 Sam
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Template Haskell and Types

2005-09-12 Thread Cale Gibbard
I'm not exactly sure what it is that you're trying to do with that
code, but here's an approximation to that code which prints the
Template Haskell representation of the type MyData:

import Language.Haskell.TH
import Monad

data MyData = MyData1 | MyData2

main = do putStrLn $(liftM (LitE . stringL . show) [t|MyData|])

by the way -- does anyone happen to know why Q isn't an instance of
Functor? It's obviously a functor by virtue of being a monad.
 - Cale

On 12/09/05, Gracjan Polak <[EMAIL PROTECTED]> wrote:
> 
> Hi,
> 
> Probably very simple question about template haskell: How do I make a
> type for an argument to splice? Example:
> 
> data MyData = MyData1 | MyData2
> 
> mysplice mytype =
> [| litE $ stringL $ show mytype |]
> 
> main = do
> putStrLn $(mysplice MyData)
> 
> 
> The above is not accepted, error:
> 
> Compiling Main ( thtest.hs, thtest.o )
> 
> thtest.hs:51:34: Not in scope: data constructor `MyData'
> 
> So how do I provide type as an argument?
> 
> Besides: documentation that I found for th is very dated. Could somebody
> point me to something more up to date about th? Thanks!
> 
> --
> Gracjan
> 
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Fwd: [Haskell-cafe] ghc for sunos

2005-09-12 Thread Brian McQueen
After I got through the Readline complaint I got an ncurses compaint,
and decided I'd bring in Knoppix CD and make a Linux system out of my
desktop.  I bet everything will work fine on a Linux system.

Brian McQueen

On 12 Sep 2005 10:44:29 +0200, Nicolas Pelletier <[EMAIL PROTECTED]> wrote:
> Malcolm Wallace <[EMAIL PROTECTED]> writes:
> 
> > Brian McQueen <[EMAIL PROTECTED]> writes:
> >
> > > I installed it and its choking while looking for libreadline.  I'm not
> > > an admin on these machines, so my options are limited.
> >
> > You can download and install the readline library as an ordinary user,
> > in your own filespace.  Just add
> > LD_LIBRARY_PATH=/path/to/my/lib/dir
> > to your environment (and export it) before proceeding with ghc.
> 
> Also, if a lurker  is allowed to chime in, ghc seems  to insist on the
> version of libreadline to use. Newer versions provide libreadline.so.5
> and will not work. You will  need to install a readline version 4.x in
> some_dir   and  take   care   that  come_dir   is   listed  first   in
> LD_LIBRARY_PATH.
> 
> HTH.
> 
> --
> Nicolas
>
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: Fwd: [Haskell-cafe] ghc for sunos

2005-09-12 Thread Nicolas Pelletier
Malcolm Wallace <[EMAIL PROTECTED]> writes:

> Brian McQueen <[EMAIL PROTECTED]> writes:
> 
> > I installed it and its choking while looking for libreadline.  I'm not
> > an admin on these machines, so my options are limited.
> 
> You can download and install the readline library as an ordinary user,
> in your own filespace.  Just add
> LD_LIBRARY_PATH=/path/to/my/lib/dir
> to your environment (and export it) before proceeding with ghc.

Also, if a lurker  is allowed to chime in, ghc seems  to insist on the
version of libreadline to use. Newer versions provide libreadline.so.5
and will not work. You will  need to install a readline version 4.x in
some_dir   and  take   care   that  come_dir   is   listed  first   in
LD_LIBRARY_PATH.

HTH.

-- 
Nicolas
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Re: Language Workbenches - the Haskell solution?

2005-09-12 Thread Yoel Jacobsen

Hi David,

Thank you for the reference. The problem with this attitude is that the 
configuration structure is static. I would like to be able to construct 
the record structure dynamically from the configuration file..


Yoel

David Menendez wrote:

Yoel Jacobsen writes:


It seems that Martin Fowler's article "Language Workbenches: The 
killer-App for Domain Specific Languages?" - 
http://www.martinfowler.com/articles/languageWorkbench.html - has 
generated some nice dynamic solution where a configuration file is 
written in the same language as the program. Notable examples are lisp


- 

http://lispm.dyndns.org/news?ID=NEWS-2005-07-08-1 and python - 



http://billionairebusinessman.blogspot.com/2005/09/drop-that-schema-and-
put-your-hands-in.html

Have you investigated hs-plugins? One of the examples for "Plugging
Haskell In"[1] is using Haskell as a configuration language.

[1] 


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Language Workbenches - the Haskell solution?

2005-09-12 Thread Yitzchak Gale
Ralf Lammel wrote:

>> XML... I wonder whether they discuss it...

yoann padioleau wrote:

> Yes, fowler mentionned XML: "XML has its uses,
> but isn't exactly easy to read..."  I dont think
> XML is a good idea for files that are
> managed/edited by humans.

It can be very human readable if set up properly.

I once set up a configurations system like that
for a large C++ app. The config files are very
readable, and easy to edit using widely available
free XML editors. For example, in the
configuration file you have things like:

25
F

  Cleveland
  Ohio


etc.

With the source code, there is a master XML
document that sets up the fields:



  F
  M


  
  

and then you can access the fields in the C++ code
as Config.Age, Config.Location.City,
Config.Location.State, etc., with the proper type.
The configuration file is verified and
type-checked at run time.  To add trees and
fields, you just edit the master XML and type
make.

If you want a GUI for configuration, you could,
for example, write a fairly simple transformation
of the master XML into a .NET dialog, or glade
file for GTK, or whatever. We never did that,
though.

It took some time to set up, but it works great.
My developers and my users loved it. It was done
for a company, so I can't release the code, but
you get the idea. You could obviously do the same
thing easily in Haskell, probably with less work.

Of course, the portablity of XML is illusory. This
is my own proprietary usage of XML, so you would
still need to write the code to support it in any
given language. (I didn't use "standards" like
DTD, XML Schema, etc., for the very reason
mentioned - human readability was a requirement.)
The result would be just as portable if you used
any other simple syntax - based on Python,
Haskell, or anything else.

If you want Haskell syntax, another idea might be
to use Haskell's built-in Haskell parser. As long
as you limit yourself to simple syntax, it would
be easy enough to process the resulting syntax
tree.

Another approach which IS portable, though in a
different sense, is to write the configuration
file in N3. That is very human readable, and then
at least some of the information in the
configuration file might be usable in a meaningful
way by other applications.

Regards,
Yitz
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Where to start about writing web/HTTP apps ?

2005-09-12 Thread Sam Mason
gary ng wrote:
>I want to write apps for WEB and have briefly read
>WASH.

I'm thinking of doing the same.  The approach taken by WASH seems very
cool and I'd love to use it.  I've only started looking at it, but
WASH seems to require that JavaScript be enabled on the user's web
browser, even for the simplest forms.  e.g. from the authors web page:

  http://nakalele.informatik.uni-freiburg.de/cgi/WASH/Counter.cgi

Also, the error checking doesn't seem to work as I'd expect:  if
you submit a page without a required field it will complain the
first time, then make something up the second time around -- even
if you haven't entered anything in the field.


  Sam
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Template Haskell and Types

2005-09-12 Thread Gracjan Polak


Hi,

Probably very simple question about template haskell: How do I make a 
type for an argument to splice? Example:


data MyData = MyData1 | MyData2

mysplice mytype =
   [| litE $ stringL $ show mytype |]

main = do
   putStrLn $(mysplice MyData)


The above is not accepted, error:

Compiling Main ( thtest.hs, thtest.o )

thtest.hs:51:34: Not in scope: data constructor `MyData'

So how do I provide type as an argument?

Besides: documentation that I found for th is very dated. Could somebody 
point me to something more up to date about th? Thanks!


--
Gracjan

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Language Workbenches - the Haskell solution?

2005-09-12 Thread Ralf Lammel








Yoann,

 

 

Thanks for your comments.

 

Yoann wrote: I don’t think XML is a good idea
for files that are managed/edited by humans.

I think the users prefer simpler files with a custom
syntax, and the user is the king.

 

I don’t mind, but when you say “user” do you mean “application
configuration admin” or “plain application user”. The former
may know/like/dislike PL syntax, the latter may not like *anything* but very simple and foolproof formats
or GUI-based configuration. There is no reason to believe that the latter wants
to feel like programming in Haskell, Java, … at least not in the universe
I live in or that I observe.

 

Yoann wrote: Of course the job of the programmer is
easier when the file is coded in XML, …

 

This is unrelated to what I said. Perhaps my wording wasn’t clear
enough. I was trying to refer to the software life cycle and tool support as a
whole. Doing software re-engineering for configurations that are formulated in
a Turing-complete language is no fun. This is quite similar to the known issues
with macros, when used for configuration; you may want to read about software
asbestos here: http://homepages.cwi.nl/~ralf/am/ 

 

Yoann wrote: I am a programmer and personally I don’t
want to code my Haskell code in XML

 

I didn’t propose *that*.
Anyway, picking up the new subject that you introduced accidentally, let me reply:
you are not alone: most programmers don’t like to code their PL code in
XML. (As an aside, XML is used even for coding these days, just in case you don’t
know: check out some widely used AOP language extensions for Java. I am not
saying whether I like this or not.)

 

Yoann wrote: so I presume it is the same for the user
with configuration files.

 

So you presume that a user of application XYZ prefers to configure
his/her application in the syntax of the underlying implementation language,
supposing there is just one? That’s a very interesting presumption. Have
you any data to substantiate your presumption, or is that a prediction for the
future?

 

Yoann wrote: if your programming langage is lisp in
which case parsing the configuration file is just a call to read.

 

Sure! Sounds a bit like comparing apples and oranges. I can also parse
my configuration file to “Data.Tree String” in Haskell, or
something similarly weakly typed. Then parsing is just a call to read, too. (Lisp
really doesn’t score here.) So what’s the point? I guess we won’t
be happy with that Haskell solution, or at least we would like to see whether
we can score with Haskell in some way.

 

Ralf

 






___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Language Workbenches - the Haskell solution?

2005-09-12 Thread yoann padioleau
On 12 sept. 05, at 00:50, Ralf Lammel wrote:- XML wasn't mentioned in your message. I wonder whether they discuss itin the actual thread. (Yes, you might be saying XML is not the sameYes, fowler mentionned XML: "XML has its uses, but isn't exactly easy to read. We could make it easier to see what's going on by using a custom syntax. Perhaps like this:"I dont think XML is a good idea for files that are managed/edited by humans.Of course the job of the programmer is easier when the file is coded in XML, but I think the user prefer simpler files with a custom syntax, andthe user is the king.I am a programmer and personnaly I dont want to code my haskell code in XML, so I presume it is the same for the user with configuration files. language as you are programming in, but it so easy to process XML inmany languages, and one uses XSD for the DSL syntax). In fact, inHaskell I would strongly consider using HaXML or similar technology fornon-trivial configuration problems. XML makes configuration also moreportable. In reality, I don't see much value in using the programminglanguage syntax for representing the configuration information. Thismakes it only harder to process those configurations with other tools.Well except if your programming langage is lisp in which case parsing the configuration file is just a call to read.Ralf___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Where to start about writing web/HTTP apps ?

2005-09-12 Thread Dean Herington

At 11:44 PM + 9/10/05, Thomas Spriggs wrote:

From: gary ng <[EMAIL PROTECTED]>

fac n = foldr (\x g n -> g (x*n)) id [1..n] 1



Would appreciate if someone can knock on my head and
tell me what is going on in it.
Well, here goes. The way the lambda function/foldr thing evaluates, 
the resulting foldl like function needs a new identity parameter 
hence the additional "1". To demonstrate something like how this is 
evaluated for a low number eg 3: (Please would someone correct me if 
I have made a mistake in this)

fac 3 = (foldr (\x g n -> g (x*n)) id [1..3]) 1
fac 3 = (foldr (\x g n -> g (x*n)) id [1,2,3]) 1
fac 3 = (foldr (\x g n -> g (x*n)) (\n -> id (3*n)) [1,2])) 1
fac 3 = (foldr (\x g n -> g (x*n)) (\n -> (\n -> id (3*n)) (2*n)) [1]) 1
fac 3 = (foldr (\x g n -> g (x*n)) (\n -> (\n -> (\n -> id (3*n)) 
(2*n)) (1*n)) []) 1

fac 3 = (\n -> (\n -> (\n -> id (3*n)) (2*n)) (1*n)) 1
fac 3 = (\n -> (\n -> id (3*n)) (2*n)) (1*1)
fac 3 = (\n -> (\n -> id (3*n)) (2*n)) 1
fac 3 = (\n -> id (3*n)) (2*1)
fac 3 = (\n -> id (3*n)) 2
fac 3 = id (3*2)
fac 3 = id 6
fac 3 = 6


Your equations are correct, but I find the (first part of the) 
sequence a bit confusing because it doesn't follow directly from the 
definition of foldr.  Here's how I would explain it:


From the prelude definition:
foldr f z [] = z
foldr f z (x:xs) = f x (foldr f z xs)

Rewriting for conciseness:
fac n = (ffz [1..n]) 1  where ffz = foldr (\x g n -> g (x*n)) id

fac 3 = (ffz [1,2,3]) 1
  = (\n1 -> (ffz [2,3]) (1*n1)) 1
  = (\n1 -> (\n2 -> (ffz [3]) (2*n2)) (1*n1)) 1
  = (\n1 -> (\n2 -> (\n3 -> (ffz []) (3*n3)) (2*n2)) (1*n1)) 1
  = (\n1 -> (\n2 -> (\n3 -> id (3*n3)) (2*n2)) (1*n1)) 1
  = (\n2 -> (\n3 -> id (3*n3)) (2*n2)) (1*1)
  = (\n3 -> id (3*n3)) (2*(1*1))
  = id (3*(2*(1*1)))
  = (3*(2*(1*1)))
  = 6
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe