6

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.

ivanTheTerrible
  • 2,836
  • 4
  • 25
  • 25
  • 2
    ASP.NET MVC + F# would be a good match. – R. Martinho Fernandes Dec 02 '09 at 21:06
  • @Martinho: That would make a good answer. – Chuck Dec 02 '09 at 21:08
  • 2
    yahoo stores was originally written with lisp. There's a famous paul graham article about it. http://www.paulgraham.com/avg.html – Breton Dec 02 '09 at 21:09
  • Martinho: ...especially with the F# Web Tools (http://www.codeplex.com/fswebtools) – itowlson Dec 02 '09 at 21:09
  • @Martinho but then you'd be using ASP.NET, thus cancelling out most benefits you may have gained from using a functional language. – Breton Dec 02 '09 at 21:11
  • 2
    @Breton: ASP.NET MVC is not like its "evil" brother ASP.NET Web Forms. I don't see you losing anything from a functional language just for using an MVC web framework. – R. Martinho Fernandes Dec 02 '09 at 21:17
  • Keep in mind that F# is a .NET product inspired (at least partially) by other languages such as Haskell. I can certainly understand not wanting the lock in (not to mention price!) .NET entails. – Bryan McLemore Dec 02 '09 at 21:39
  • 1
    F# is much more strongly influenced by OCaml than Haskell. It's basically a stripped-down OCaml with better libraries. The only Haskell influence I see is that it has built-in composition and application operators. – Chuck Dec 02 '09 at 21:48
  • 2
    You might be better off learning your functional language in a different context - web development IS a decent realm for functional programming, but unless you're following a course of study, you'll find the discipline really confusing. Building web pages won't explicitly teach you the really important bits. Take a look at SICP and brethren. http://mitpress.mit.edu/sicp/ – Paul McMillan Dec 02 '09 at 22:06
  • @ivanTheTerrible (the original poster): F# is available for Mono, so it doesn't tie you in to Microsoft. – harms Dec 02 '09 at 22:47
  • @harms Have you ever actually tried mono? How compatible is it really? I don't really have a lot of faith in the ".NET doesn't tie you to windows at all!" assertion. The argument has never made any sense to me, and has always had a curious lack of evidence. – Breton Dec 02 '09 at 23:56
  • @Breton: I don't have enough first-hand experience myself to vouch for it, but I have briefly tried F# on Mono on my Mac. I also know that a number of widely used and popular apps in the Gnome desktop environment which are written in Mono using C#. I guess you're better served by looking at this question: http://stackoverflow.com/questions/18450/is-mono-ready-for-prime-time – harms Dec 14 '09 at 21:54

10 Answers10

10

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
  • 234,037
  • 30
  • 302
  • 389
6

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.

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
4

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
  • 41
  • 1
  • I wouldn't say Lift is similar to Rails. Lift is a web framework for Scala but primarily focuses on a "view-first" methodology where as Rails is MVC. See http://www.assembla.com/spaces/liftweb/wiki/View_First – Travis Aug 01 '11 at 22:05
3

With Haskell it's 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).

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
        ]
    ]
icc97
  • 11,395
  • 8
  • 76
  • 90
Caleb
  • 9,272
  • 38
  • 30
3

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
  • 6,438
  • 1
  • 26
  • 30
  • 1
    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 Dec 02 '09 at 23:29
2
  • 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
  • 143,651
  • 25
  • 248
  • 329
2

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
  • 39,360
  • 16
  • 67
  • 93
2

Yesod in Haskell is past 1.0.


(Putting this late answer in only because Google is still showing people (like me) this old question.)

isomorphismes
  • 8,233
  • 9
  • 59
  • 70
0

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
  • 726
  • 6
  • 13
-1

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
  • 15,847
  • 1
  • 38
  • 65