Re: [Haskell-cafe] Is it possible to "easily" connect Haskell to JavaScript/JavaFX in the browser and use a browser as a Windows GUI? :)

Quoting Aleksandar Dimitrov
Hi,
Is it possible to "easily" connect Haskell to JavaScript/JavaFX in the browser and use a browser as a Windows GUI? :)
I don't exactly know what you mean by "connect," but here's an LtU thread that might give you some hints: http://lambda-the-ultimate.org/node/1836
Regards, Aleks
I meant call Haskell functions from a browser; so the browser handles the GUI widgets and Haskell handles the processing. :)

caseyh@istar.ca wrote:
Is it possible to "easily" connect Haskell to JavaScript/JavaFX in the browser and use a browser as a Windows GUI? :) ... I meant call Haskell functions from a browser; so the browser handles the GUI widgets and Haskell handles the processing. :)
It's pretty easy to get the basics going. There are a bunch of options. Start here: http://www.haskell.org/haskellwiki/Web For what you're asking about, I'd suggest looking at the following options from that page. All of these options involve linking a web server library into your Haskell app, so it's self-contained and all you need is a browser to talk to it: #6: Snap + custom code: Snap is simple to get started with, and is good if you know exactly what HTML/Javascript you need to generate and don't mind doing it more or less manually. If you're looking for richer library support for developing HTML UIs, consider the next option. #2: Snap + Yesod: Yesod will give you many of the framework features you might want for developing web UIs. (Not sure about JavaFX though.) #1: Happstack: an ambitious web server / framework with some fancy features like its own data persistence system. One other tool worth considering if you're doing a lot of Javascript with Haskell is JMacro: http://www.haskell.org/haskellwiki/Jmacro It lets you embed Javascript code directly in Haskell, and easily embed Haskell data into that code. Anton

On 20/10/2010 09:48 PM, Anton van Straaten wrote:
It's pretty easy to get the basics going. There are a bunch of options. Start here:
http://www.haskell.org/haskellwiki/Web
For what you're asking about, I'd suggest looking at the following options from that page. All of these options involve linking a web server library into your Haskell app, so it's self-contained and all you need is a browser to talk to it:
#6: Snap + custom code: Snap is simple to get started with, and is good if you know exactly what HTML/Javascript you need to generate and don't mind doing it more or less manually. If you're looking for richer library support for developing HTML UIs, consider the next option.
#2: Snap + Yesod: Yesod will give you many of the framework features you might want for developing web UIs. (Not sure about JavaFX though.)
#1: Happstack: an ambitious web server / framework with some fancy features like its own data persistence system.
One other tool worth considering if you're doing a lot of Javascript with Haskell is JMacro: http://www.haskell.org/haskellwiki/Jmacro
It lets you embed Javascript code directly in Haskell, and easily embed Haskell data into that code.
I'd like to have a go at writing CGI in Haskell. However, I don't really want to install and configure the likes of Apache just to quickly test a simple CGI script. I was hoping that I could find a trivial little HTTP server on Hackage somewhere that would be just a simple binary that I can execute and feed CGI binaries to. But alas, the closest thing I can find is http://hackage.haskell.org/package/hws Alas, this does not work on Windows since it depends on the "unix" package. (In fact, almost every network-related package on Hackage depends on "unix", for reasons beyond my powers of comprehension...) (I also looked at non-Haskell lightweight web servers, but they all unanimously don't support CGI at all, or only support CGI _scripts_, but arbitrary executables...) Does anybody know of a solution that works on Windows?

You can use Network.Wai.Handler.SimpleServer from wai-extra[1]. If you
want a full framework, Yesod[2] has full Windows support.
Michael
[1] http://hackage.haskell.org/cgi-bin/hackage-scripts/package/wai-extra
[2] http://docs.yesodweb.com/
On Wed, Oct 20, 2010 at 11:10 PM, Andrew Coppin
On 20/10/2010 09:48 PM, Anton van Straaten wrote:
It's pretty easy to get the basics going. There are a bunch of options. Start here:
http://www.haskell.org/haskellwiki/Web
For what you're asking about, I'd suggest looking at the following options from that page. All of these options involve linking a web server library into your Haskell app, so it's self-contained and all you need is a browser to talk to it:
#6: Snap + custom code: Snap is simple to get started with, and is good if you know exactly what HTML/Javascript you need to generate and don't mind doing it more or less manually. If you're looking for richer library support for developing HTML UIs, consider the next option.
#2: Snap + Yesod: Yesod will give you many of the framework features you might want for developing web UIs. (Not sure about JavaFX though.)
#1: Happstack: an ambitious web server / framework with some fancy features like its own data persistence system.
One other tool worth considering if you're doing a lot of Javascript with Haskell is JMacro: http://www.haskell.org/haskellwiki/Jmacro
It lets you embed Javascript code directly in Haskell, and easily embed Haskell data into that code.
I'd like to have a go at writing CGI in Haskell. However, I don't really want to install and configure the likes of Apache just to quickly test a simple CGI script. I was hoping that I could find a trivial little HTTP server on Hackage somewhere that would be just a simple binary that I can execute and feed CGI binaries to. But alas, the closest thing I can find is
http://hackage.haskell.org/package/hws
Alas, this does not work on Windows since it depends on the "unix" package. (In fact, almost every network-related package on Hackage depends on "unix", for reasons beyond my powers of comprehension...)
(I also looked at non-Haskell lightweight web servers, but they all unanimously don't support CGI at all, or only support CGI _scripts_, but arbitrary executables...)
Does anybody know of a solution that works on Windows?
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Andrew Coppin wrote:
I'd like to have a go at writing CGI in Haskell. ... Does anybody know of a solution that works on Windows?
I've previously run Happstack on Windows. That was a couple of years ago, though, so I don't know whether its Windows support is currently working.

On Oct 20, 2010, at 7:28 PM, Anton van Straaten wrote:
Andrew Coppin wrote:
I'd like to have a go at writing CGI in Haskell. ... Does anybody know of a solution that works on Windows?
I've previously run Happstack on Windows. That was a couple of years ago, though, so I don't know whether its Windows support is currently working.
It should work. Windows is an officially supported happstack platform. All releases are tested to ensure they work under Windows. - jeremy

On 21/10/2010 01:28 AM, Anton van Straaten wrote:
Andrew Coppin wrote:
I'd like to have a go at writing CGI in Haskell. ... Does anybody know of a solution that works on Windows?
I've previously run Happstack on Windows. That was a couple of years ago, though, so I don't know whether its Windows support is currently working.
My understanding is that Happstack is a very large, powerful and complex framework for writing Haskell web applications. I was under the impression that you use it by statically linking the HTTP server and the actual application together, rather than Happstack providing a standard CGI interface that an external application can then use.

On Thu, Oct 21, 2010 at 12:04 PM, Andrew Coppin
My understanding is that Happstack is a very large, powerful and complex framework for writing Haskell web applications. I was under the impression that you use it by statically linking the HTTP server and the actual application together, rather than Happstack providing a standard CGI interface that an external application can then use.
powerful - yes! large and complex -- not so much. Though, the lower bound on complexity is limited by the fundamental complexity of the web itself. But, you are correct that happstack does not currently have support for running CGI executables. I imagine that you could write a CGI handler (with out modifying the core code) in a few hours (maybe less). Mostly just a matter of turning the values in the Request type into a environment variables, and calling the executable? That said, I am not sure why you want CGI. CGI is only simple in the sense that it doesn't do anything for you. But that means you have to handle all the complexity yourself. Perhaps it would be easier to just learn happstack. It is much better documented now than it was a few years ago (and some aspects have been simplified). And happstack-state and happstack-server are now completely independent. Here is a nice tutorial, http://happstack.com/docs/crashcourse/index.html The darcs version (which will be released soon) has much better haddock documentation as well. I would recommend the darcs version for any new development. - jeremy

On Thu, Oct 21, 2010 at 8:00 PM, Jeremy Shaw
On Thu, Oct 21, 2010 at 12:04 PM, Andrew Coppin
wrote: My understanding is that Happstack is a very large, powerful and complex framework for writing Haskell web applications. I was under the impression that you use it by statically linking the HTTP server and the actual application together, rather than Happstack providing a standard CGI interface that an external application can then use.
powerful - yes! large and complex -- not so much. Though, the lower bound on complexity is limited by the fundamental complexity of the web itself.
But, you are correct that happstack does not currently have support for running CGI executables. I imagine that you could write a CGI handler (with out modifying the core code) in a few hours (maybe less). Mostly just a matter of turning the values in the Request type into a environment variables, and calling the executable?
That said, I am not sure why you want CGI. CGI is only simple in the sense that it doesn't do anything for you. But that means you have to handle all the complexity yourself. Perhaps it would be easier to just learn happstack. It is much better documented now than it was a few years ago (and some aspects have been simplified). And happstack-state and happstack-server are now completely independent.
Here is a nice tutorial, http://happstack.com/docs/crashcourse/index.html The darcs version (which will be released soon) has much better haddock documentation as well. I would recommend the darcs version for any new development.
Shouldn't it be possible to plug in the happstack-wai experimental port with Network.Wai.Handler.CGI and then both get the power of Happstack *and* easy CGI support? And then later on, when ready to move past CGI it will be easy to move to a better deployment option. Michael

On 21/10/2010 07:00 PM, Jeremy Shaw wrote:
But, you are correct that happstack does not currently have support for running CGI executables. I imagine that you could write a CGI handler (with out modifying the core code) in a few hours (maybe less). Mostly just a matter of turning the values in the Request type into a environment variables, and calling the executable?
And writing a HTTP server is "mostly" a matter of parsing the request headers and constructing some response headers. However, this turns out to be significantly less easy to do properly than you'd first imagine. ;-)
That said, I am not sure why you want CGI.
Because my hired web server runs Apache? Sure, if I'm only doing stuff on the local machine, I can use any kind of server/application linkage I like, because I can use any server I want. But if I ever decide to actually put this stuff on the web, for real, it'll have to be plain CGI. (Or maybe FastCGI is supported, I'm not actually sure...) That being the case, I might as well develop it as CGI to start with.

On Fri, Oct 22, 2010 at 12:05 PM, Andrew Coppin
On 21/10/2010 07:00 PM, Jeremy Shaw wrote:
But, you are correct that happstack does not currently have support for running CGI executables. I imagine that you could write a CGI handler (with out modifying the core code) in a few hours (maybe less). Mostly just a matter of turning the values in the Request type into a environment variables, and calling the executable?
And writing a HTTP server is "mostly" a matter of parsing the request headers and constructing some response headers. However, this turns out to be significantly less easy to do properly than you'd first imagine. ;-)
True. Though I am basing my assumption on the fact that we have code which goes the opposite way (allows happstack to run as a CGI process), and those bindings are pretty short (less than 100 lines) and simple looking.
That said, I am not sure why you want CGI.
Because my hired web server runs Apache?
Sure, if I'm only doing stuff on the local machine, I can use any kind of server/application linkage I like, because I can use any server I want. But if I ever decide to actually put this stuff on the web, for real, it'll have to be plain CGI. (Or maybe FastCGI is supported, I'm not actually sure...) That being the case, I might as well develop it as CGI to start with.
happstack-server has FastCGI support. Plain-old CGI support is no great challenge either. Your web application is basically just a , ServerPart Response, value. Typically you would run that using simpleHTTP simpleHTTP :: (ToMessage a) => Conf -> ServerPart a -> IO () but you can just as easily run it as CGI using: serverPartToCGI :: ToMessage a => ServerPart a -> CGI CGIResult (from the happstack-fastcgi package). - jeremy

Andrew Coppin schrieb:
I'd like to have a go at writing CGI in Haskell. However, I don't really want to install and configure the likes of Apache just to quickly test a simple CGI script. I was hoping that I could find a trivial little HTTP server on Hackage somewhere that would be just a simple binary that I can execute and feed CGI binaries to. But alas, the closest thing I can find is
http://hackage.haskell.org/package/hws
Alas, this does not work on Windows since it depends on the "unix" package. (In fact, almost every network-related package on Hackage depends on "unix", for reasons beyond my powers of comprehension...)
(I also looked at non-Haskell lightweight web servers, but they all unanimously don't support CGI at all, or only support CGI _scripts_, but arbitrary executables...)
In MoHWS there is code for running Haskell code as CGI code via hs-plugins. I think it must be updated to GHC-API in order to be still usable. However, I do not really understand what kind of CGI do you want or do not want.
participants (6)
-
Andrew Coppin
-
Anton van Straaten
-
caseyh@istar.ca
-
Henning Thielemann
-
Jeremy Shaw
-
Michael Snoyman