The fn package


Please see README.

[Skip to ReadMe]


Dependenciesbase (>=4.7 && <5), blaze-builder, bytestring, http-types, text, wai [details]
Copyright2015 Daniel Patterson
AuthorDaniel Patterson <>
Home page
Source repositoryhead: git clone
UploadedSun Oct 25 19:13:49 UTC 2015 by DanielPatterson




Maintainers' corner

For package maintainers and hackage trustees

Readme for fn-

Fn (eff-enn) - a functional web framework.

Or, how to do away with the monad transformers, and just use plain functions.


See the example application in the repository for a full usage, but a minimal application is the following:

{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TemplateHaskell   #-}

import           Control.Lens
import           Data.Monoid
import           Data.Text                (Text)
import qualified Data.Text                as T
import           Network.HTTP.Types
import           Network.Wai
import           Network.Wai.Handler.Warp
import qualified Network.Wai.Util         as W
import           Web.Fn

data Ctxt = Ctxt { _req :: Request

makeLenses ''Ctxt

instance RequestContext Ctxt where
  requestLens = req

initializer :: IO Ctxt
initializer = return (Ctxt defaultRequest)

main :: IO ()
main = do context <- initializer
          run 8000 $ toWAI context app

app :: Ctxt -> IO Response
app ctxt =
  route ctxt [ end ==> index
             , path "foo" // segment // path "baz" /? param "id" ==> handler]
    `fallthrough` notFoundText "Page not found."

index :: IO (Maybe Response)
index = okText "This is the index page! Try /foo/bar/baz?id=10"

handler :: Ctxt -> Text -> Int -> IO (Maybe Response)
handler _ fragment i = okText (fragment <> " - " <> T.pack (show i))

Recommended Pairings

Part of the design of Fn is that you won't need a suite of fn-foo libraries that generally serve to adapt the functions from foo to the monad transformer stack of the web framework of choice (we may add a fn-extra package with a few helpers in it in the future, but it'll be small). Still, it's helpful to know what are common tools that are well designed and tested, so here are a list (those marked with [*] are used in the example application included in this repository):