From: PHO Date: Tue, 29 Nov 2011 14:52:38 +0000 (+0900) Subject: docs X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=Lucu.git;a=commitdiff_plain;h=251831f3e465eb77666193efcb9b4c02531faa6c docs Ditz-issue: e0312227f40a0fa92d4c5d69a64dad473f54389a --- diff --git a/Data/Collections/Newtype/TH.hs b/Data/Collections/Newtype/TH.hs index c60ea2b..0301fd3 100644 --- a/Data/Collections/Newtype/TH.hs +++ b/Data/Collections/Newtype/TH.hs @@ -2,7 +2,9 @@ TemplateHaskell , UnicodeSyntax #-} --- |FIXME: doc +-- |Doesn't anyone know why these instances can't be derived using +-- GeneralizedNewtypeDeriving? I think its limitation isn't reasonable +-- at all... module Data.Collections.Newtype.TH ( derive ) @@ -27,7 +29,42 @@ import Prelude.Unicode type Deriver = Q Cxt → Q Type → Q Exp → Q Exp → Q Dec --- |FIXME: doc +-- |Automatic newtype instance deriver for type classes defined by the +-- collections-api package. +-- +-- @ +-- {-\# LANGUAGE TemplateHaskell \#-} +-- module Foo (T) where +-- import "Data.Collections" +-- import "Data.Collections.BaseInstances" () +-- import qualified Data.Collections.Newtype.TH as C +-- import qualified "Data.Map" as M +-- +-- newtype T = T (M.Map 'Int' 'Bool') +-- +-- C.derive [d| instance 'Unfoldable' T ('Int', 'Bool') +-- instance 'Foldable' T ('Int', 'Bool') +-- instance 'Indexed' T 'Int' 'Bool' +-- ... +-- |] +-- @ +-- +-- This function can derive the following instances: +-- +-- * 'Unfoldable' +-- +-- * 'Foldable' +-- +-- * 'Collection' +-- +-- * 'Indexed' +-- +-- * 'Map' +-- +-- * 'Set' +-- +-- * 'SortingCollection' +-- derive ∷ Q [Dec] → Q [Dec] derive = (concat <$>) ∘ (mapM go =≪) where diff --git a/Lucu.cabal b/Lucu.cabal index 8703d04..7773f80 100644 --- a/Lucu.cabal +++ b/Lucu.cabal @@ -83,6 +83,7 @@ Library -DHAVE_SSL Exposed-Modules: + Data.Collections.Newtype.TH Network.HTTP.Lucu Network.HTTP.Lucu.Abortion Network.HTTP.Lucu.Authentication @@ -113,7 +114,6 @@ Library Network.HTTP.Lucu.Utils Other-Modules: - Data.Collections.Newtype.TH Network.HTTP.Lucu.Abortion.Internal Network.HTTP.Lucu.Chunk Network.HTTP.Lucu.ContentCoding diff --git a/Network/HTTP/Lucu/Httpd.hs b/Network/HTTP/Lucu/Httpd.hs index ac1dc77..0d78f98 100644 --- a/Network/HTTP/Lucu/Httpd.hs +++ b/Network/HTTP/Lucu/Httpd.hs @@ -28,26 +28,28 @@ import Prelude.Unicode -- -- Example: -- --- > {-# LANGUAGE OverloadedStrings #-} --- > {-# LANGUAGE QuasiQuotes #-} --- > module Main where --- > import Network --- > import Network.HTTP.Lucu --- > --- > main :: IO () --- > main = let config = defaultConfig --- > resources = mkResTree [ ([], helloWorld) ] --- > in --- > withSocketsDo $ runHttpd config resourcees [] --- > --- > helloWorld :: Resource --- > helloWorld = emptyResource { --- > resGet --- > = Just $ do setContentType [mimeType| text/plain |] --- > putChunk "Hello, world!" --- > } +-- @ +-- {-\# LANGUAGE OverloadedStrings \#-} +-- {-\# LANGUAGE QuasiQuotes \#-} +-- module Main where +-- import qualified "Data.Collections" as C +-- import "Network" +-- import "Network.HTTP.Lucu" -- --- FIXME: update the above example +-- main :: 'IO' () +-- main = let config = 'defaultConfig' +-- tree :: 'ResourceTree' +-- tree = C.fromList [ ([], 'nonGreedy' helloWorld) ] +-- in +-- 'Network.withSocketsDo' '$' 'runHttpd' config '$' 'resourceMap' tree +-- +-- helloWorld :: 'Network.HTTP.Lucu.Resource' +-- helloWorld = C.fromList +-- [ ( 'Network.HTTP.Lucu.GET' +-- , do 'Network.HTTP.Lucu.setContentType' ['Network.HTTP.Lucu.mimeType'| text/plain |] +-- 'Network.HTTP.Lucu.putChunk' \"Hello, world!\" +-- } +-- @ runHttpd ∷ HostMapper α ⇒ Config → α → IO () runHttpd cnf hm = do let launchers diff --git a/examples/HelloWorld.hs b/examples/HelloWorld.hs index 6a73256..2d240e8 100644 --- a/examples/HelloWorld.hs +++ b/examples/HelloWorld.hs @@ -8,6 +8,7 @@ import Control.Monad.Unicode import qualified Data.ByteString.Lazy.Char8 as Lazy import qualified Data.Collections as C import Data.Monoid.Unicode +import Network import Network.HTTP.Lucu import Prelude.Unicode @@ -27,7 +28,7 @@ main = let config = defaultConfig { cnfServerPort = "9999" } | otherwise = Nothing in do putStrLn "Access http://localhost:9999/ with your browser." - runHttpd config mapper + withSocketsDo $ runHttpd config mapper helloWorld ∷ Resource helloWorld = C.fromList diff --git a/examples/Implanted.hs b/examples/Implanted.hs index 9259c13..03bcbdb 100644 --- a/examples/Implanted.hs +++ b/examples/Implanted.hs @@ -3,6 +3,7 @@ #-} import qualified Data.Collections as C import MiseRafturai +import Network import Network.HTTP.Lucu main ∷ IO () @@ -11,4 +12,4 @@ main = let config = defaultConfig { cnfServerPort = "9999" } tree = C.fromList [ ([], nonGreedy miseRafturai) ] in do putStrLn "Access http://localhost:9999/ with your browser." - runHttpd config $ resourceMap tree + withSocketsDo $ runHttpd config $ resourceMap tree diff --git a/examples/ImplantedSmall.hs b/examples/ImplantedSmall.hs index f7e8856..ba9b5b9 100644 --- a/examples/ImplantedSmall.hs +++ b/examples/ImplantedSmall.hs @@ -2,6 +2,7 @@ UnicodeSyntax #-} import qualified Data.Collections as C +import Network import Network.HTTP.Lucu import SmallFile @@ -11,4 +12,4 @@ main = let config = defaultConfig { cnfServerPort = "9999" } tree = C.fromList [ ([], nonGreedy smallFile) ] in do putStrLn "Access http://localhost:9999/ with your browser." - runHttpd config $ resourceMap tree + withSocketsDo $ runHttpd config $ resourceMap tree diff --git a/examples/Multipart.hs b/examples/Multipart.hs index 49945ec..e827ae6 100644 --- a/examples/Multipart.hs +++ b/examples/Multipart.hs @@ -8,6 +8,7 @@ import qualified Data.Collections as C import Control.Monad.Unicode import Data.Maybe import Data.Monoid.Unicode +import Network import Network.HTTP.Lucu main ∷ IO () @@ -16,7 +17,7 @@ main = let config = defaultConfig { cnfServerPort = "9999" } tree = C.fromList [ ([], nonGreedy resMain) ] in do putStrLn "Access http://localhost:9999/ with your browser." - runHttpd config $ resourceMap tree + withSocketsDo $ runHttpd config $ resourceMap tree resMain ∷ Resource resMain = C.fromList diff --git a/examples/SSL.hs b/examples/SSL.hs index 23de8b0..624ed04 100644 --- a/examples/SSL.hs +++ b/examples/SSL.hs @@ -10,6 +10,7 @@ import Control.Monad.Unicode import qualified Data.ByteString.Lazy.Char8 as Lazy import qualified Data.Collections as C import Data.Time.Clock +import Network import Network.HTTP.Lucu import OpenSSL import OpenSSL.EVP.PKey @@ -37,7 +38,7 @@ main = withOpenSSL $ tree ∷ ResourceTree tree = C.fromList [ ([], nonGreedy helloWorld) ] putStrLn "Access https://localhost:9001/ with your browser." - runHttpd config $ resourceMap tree + withSocketsDo $ runHttpd config $ resourceMap tree helloWorld ∷ Resource helloWorld