views:

321

answers:

9

I'd like to start doing some forms of web development, with the aim of building web apps that could eventually grow into start-up products. And for a long time, I have been very curious about functional programming, and somewhere in my heart secretly believing that higher up you go in the abstraction level, the more power you have (hidden presumption: functional programming is more abstract than procedural).

So given the little web develop experience I have, is there any functional language/framework good to start with, for learning web development?

Alternative is to stick with a matured procedural web framework (probably Django), learn the ropes of web developments first, then think about functional programming. However, all the work would be "wasted" if I do eventually switch to functional programming.

I have pretty good experience with C++, Objective-C/Cocoa, familiar with Python.

EDIT: Many people suggest F#. But I would love to (with no offense to others), stay away from .NET platform and other MS ecosystems.

+2  A: 

Its certainly possible to use CGI to write web applications. See:

Though with haskell the applications need to be compiled and deployed (either compiled on the server or in an environment similar to the server's). More info here.

I recently played around with this... overall I felt it wasn't all that much harder than using a normal (statistically speaking) language. Here's an example of what the code might look like (following a sort of MVC approach):

CGI.hs:

module CGITest.CGI where

import Network.CGI
import qualified CGITest.Views as V
import qualified CGITest.Data as D

cgiMain = runCGI (handleErrors (do
 rows <- liftIO D.getAllData
 output $ V.drawPage $ V.drawTable rows
 ))

Data.hs:

module CGITest.Data where

import qualified Data.Map as Map
import Database.HDBC
import Database.HDBC.Sqlite3

getAllData :: IO [Map.Map String SqlValue]
getAllData = do
 conn <- connectSqlite3 "C:\\Personal\\code\\Code\\Haskell\\CGITest\\test.db"
 statement <- prepare conn "SELECT * FROM Test"
 execute statement []
 rows <- fetchAllRowsMap statement
 return rows

Views.hs:

module CGITest.Views where

import qualified Data.Map as Map
import Data.Map ((!))
import Prelude hiding (div, id)
import Text.HTML.Light hiding (head)
import qualified Text.HTML.Light as H
import Text.XML.Light.Types (Content)
import Text.XML.Light

import Text.JSON
import Text.JSON.String

import Database.HDBC

tbody z e = Elem (Element (unqual "tbody") z e Nothing)
thead z e = Elem (Element (unqual "thead") z e Nothing)

drawPage x = renderXHTML xhtml_1_0_transitional $
 html [] [
  H.head [] [
   title [] [cdata "Testing Haskell CGI"]
  ],
  body [] [
   div [id "outer-container"] [
    div [id "inner-container"] x,
    cdata $ show testJ
   ]
  ]
 ]

drawRow columns =
 tr [class' "row"] [
  td [] [cdata $ fromSql $ columns ! "id"],
  td [] [cdata $ fromSql $ columns ! "name"]
 ]
 where
  tId = "row-" ++ (fromSql $ columns ! "id")

drawTable rows =
 [
  table [border "1"] [
   thead [] [
    tr [] [
     th [] [cdata "ID"],
     th [] [cdata "Name"]
    ]
   ],
   tbody [] $ map drawRow rows
  ]
 ]
Caleb
also look into happstack http://happstack.com/ , has some awesome ideas behind it
barkmadley
+2  A: 
  • Ruby is somewhat functional, so you can use the highly regarded Rails framework (although it is not itself particularly functional)
  • I'm not sure how Seaside is structured internally, but it might be worth a look. (Ruby and Smalltalk are OO languages in which one can do functional programming, as opposed to being primarily functional languages.)
  • Here is a discussion on Haskell web frameworks.
DigitalRoss
+6  A: 

You could learn F# as your functional language and ASP.NET MVC as your web framework. This gives you access to the tools and libraries in the .NET framework.

I took my first steps in web development with ASP.NET MVC and I found it quite simple to start with.

And you could also have a look at the F# Web Tools, as itowlson suggested.

Martinho Fernandes
+8  A: 

You might be interested in Ocsigen, a Web framework for OCaml. OCaml is a pretty good language to learn functional programming IMO. It's really strongly functional, unlike Ruby or Python or any other imperative OO language people will try to sell you as "able to do functional programming" (by which they just mean it has first-class functions).

(Disclaimer: I haven't used Ocsigen much myself, but I have heard good things about it. It's on my list of things to do.)

Chuck
+3  A: 

This is a little off the wall and not a strict functional language but you might want to consider erlang.

Erlang has a pretty good framework named Erlyweb and it's own webserver named Yaws.

It's powerful, and offers amazing things for concurrency, but is a very large mental shift from some other languages.

Bryan McLemore
Erlang is probably my least favorite of the "mainstream" functional languages, but it's a compelling choice for Web app backends thanks to how well it scales.
Chuck
A: 

And for a long time, I have been very curious about functional programming, and somewhere in my heart secretly believing that higher up you go in the abstraction level, the more power you have (hidden presumption: functional programming is more abstract than procedural).

This "higher abstraction power" probably will only apply to the code you yourself write. Many frameworks/tools have helper such as code generation for UI data binding or database mappings. This generated code will not be functional.

I'm not aware of a web framework that's 100% functional with the same features as ASP MVC / DotNetNuke / Ruby Rails.

JasDev
+2  A: 

I'm not aware of a web framework that's 100% functional with the same power as ASP MVC / DotNetNuke / Ruby Rails.

Scala (a mixed OO and functional language) has a framework called Lift which is similar to Rails.

Tom
Is the framework strongly functional, though?
Chuck
A: 

SML server is a plugin for Apache that allows you to write in Standard ML, a general purpose functional language.

http://www.smlserver.org/

Dean J
A: 

You should probably take some time developing in Seaside first. Take a look at the tutorials James Foster wrote. It seems to be the most high-level web framework with a community

Stephan Eggermont