

Your server as a function [pdf] - steveklabnik
http://monkey.org/~marius/funsrv.pdf

======
pka
I've been thinking about structuring servers around FRP [1] and declarative
programming for a while now. FRP is based on the notion of events / signals as
first class objects and the ability to compose those; it has been gaining
popularity for client programming in recent years [2].

For example, on a very high level, an HTTP request signal function might look
like this:

    
    
      request :: Signal Request -> Signal Response
    

And a database request function might roughly look like this:

    
    
      requestDB :: Signal Query -> Signal [Record]
    

Having the basic building blocks, one could imagine building a function to
e.g. extract all users:

    
    
      extractUsers :: Signal Request -> Signal Response
      extractUsers = request . createUserQuery . requestDB . showUsers
    

Similar signal functions could theoretically be constructed for routes, system
functions, static files and so on. And since all signal functions are pure,
composing those and creating ever more powerful abstractions without having to
worry about system state and environment context may be a nicer way of doing
server programming.

[1] Functional Reactive Programming -
[http://en.wikipedia.org/wiki/Functional_reactive_programming](http://en.wikipedia.org/wiki/Functional_reactive_programming)

[2] [http://elm-lang.org](http://elm-lang.org)

~~~
PeterisP
It looks very similar to how yesod
([http://www.yesodweb.com/](http://www.yesodweb.com/),
[http://www.yesodweb.com/book/basics](http://www.yesodweb.com/book/basics))
routes/handlers are implemented - is that what you mean?

~~~
pka
Not quite - iirc Yesod still runs in some kind of IO monad, i.e. it is
stateful. In contrast signal functions are declarative (pure).

~~~
PeterisP
Interacting with a DB or reading a html file from disk is in essence non-pure.

~~~
pka
[1] is a good simple explanation of what FRP is about. A DB interaction for
example can be viewed as a pure function from a signal of Requests to a signal
of Records. Same with files (Signal Path -> Signal FileContents), etc.

[1] [http://elm-lang.org/learn/What-is-FRP.elm](http://elm-
lang.org/learn/What-is-FRP.elm)

------
dancecodes
very cool idea and also some of set of sites can be similar as pipe commands
for shell

