Permalink
Browse files

updated cabal docs

  • Loading branch information...
dorchard committed Oct 1, 2012
1 parent 49e7a06 commit 35eb7ca5d24a65592b3344f0e43a980325bc2a5b
Showing with 86 additions and 15 deletions.
  1. +2 −0 Setup.hs
  2. +47 −5 codo-notation.cabal
  3. +12 −9 edit-distance.lhs
  4. +7 −0 sample.lhs
  5. +17 −0 sample2.lhs
  6. +1 −1 src/Language/Haskell/Codo.lhs
View
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
View
@@ -1,15 +1,56 @@
name: codo-notation
version: 0.5
-synopsis: A notation for comonads, analogous to the do-notation for monads
+synopsis: A notation for comonads, analogous to the do-notation for monads.
+description: Requires the @TemplateHaskell@ and @QuasiQuotes@ extensions.
+ .
+ Example 1:
+ .
+ @
+ {-\# LANGUAGE TemplateHaskell \#-}
+ {-\# LANGUAGE QuasiQuotes \#-}
+ .
+ import Control.Comonad
+ import Language.Haskell.Codo
+ .
+ foo :: (Comonad c, Num a) => c a -> a
+ foo = [codo| x => extract x + 1 |]
+ @
+ .
+ Example 2:
+ .
+ @
+ import Data.Monoid
+
+ instance Monoid Double where
+     mempty = 0.0
+     mappend = (+)
+ .
+ differentiate f = ((f 0.001) - f 0) / 0.001
+ .
+ minima :: (Double -> Double) -> Bool
+ minima = [codo| f => f' <- differentiate f
+ &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20; f'' <- differentiate f'
+ &#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20;&#x20; (extract f' &#60; 0.001) && (extract f'' &#62; 0) |]
+ @
+ .
+ Further explanation of the syntax can be found in the following (short) paper: <http://www.cl.cam.ac.uk/~dao29/drafts/codo-notation-orchard-ifl12.pdf> with a numer of examples.
+ .
+ Further examples can be found here: <https://github.com/dorchard/codo-notation>.
+
-- description:
license: BSD3
license-file: LICENSE
-author: Dominic Orchard
-maintainer: dom.orchard@gmail.com
+author: Dominic Orchard <dom.orchard@gmail.com>
+maintainer: Dominic Orchard <dom.orchard@gmail.com>
+stability: experimental
-- copyright:
category: Language
build-type: Simple
-cabal-version: >=1.8
+cabal-version: >=1.7
+
+source-repository head
+ type: git
+ location: git://github.com/dorchard/codo-notation.git
library
exposed-modules: Language.Haskell.Codo
@@ -18,5 +59,6 @@ library
comonad >= 3,
uniplate > 1.6,
template-haskell >= 2.7,
- haskell-src-meta >= 0.5.1
+ haskell-src-meta >= 0.5.1,
+ parsec >= 3
hs-source-dirs: src
View
@@ -4,7 +4,7 @@
> {-# LANGUAGE FlexibleInstances #-}
> import Language.Haskell.Codo
-> import Control.Comonad.Alt
+> import Control.Comonad
> import Context
@@ -16,17 +16,20 @@ Comonad is a composite of InContext and product comonad
Comonad definition
> instance Comonad (DynP x) where
-> current (DynP d _ _) = current d
+> extract (DynP d _ _) = extract d
-> f <<= (DynP (InContext s c) x y) =
+> extend f (DynP (InContext s c) x y) =
> DynP (InContext (\c' -> f (DynP (InContext s c') x y)) c) x y
+> instance Functor (DynP x) where
+> fmap f = extend (f . extract)
+
Levenshtein edit-distance example
-> levenshtein :: DynP Char a -> Int
+> levenshtein :: DynP Char Int -> Int
> levenshtein = [codo| _ => -- Initialise first row and column
> d <- levenshtein _
-> dn <- (coreturn d) + 1
+> dn <- (extract d) + 1
> d0 <- (constant 0) `fbyX` dn
> d' <- d0 `fbyY` dn
> -- Shift (-1, 0), (0, -1), (-1, -1)
@@ -35,10 +38,10 @@ Levenshtein edit-distance example
> d_nw <- d !!! (-1, -1)
> -- Body
> d'' <- if (correspondingX d == correspondingY d) then
-> coreturn d_nw
-> else minimum [(coreturn d_w) + 1,
-> (coreturn d_n) + 1,
-> (coreturn d_nw) + 1]
+> extract d_nw
+> else minimum [(extract d_w) + 1,
+> (extract d_n) + 1,
+> (extract d_nw) + 1]
> d' `thenXY` d'' |]
> edit_distance x y = levenshtein <<= (DynP (InContext undefined (0, 0)) (' ':x) (' ':y))
View
@@ -0,0 +1,7 @@
+> {-# LANGUAGE TemplateHaskell #-}
+> {-# LANGUAGE QuasiQuotes #-}
+> import Control.Comonad
+> import Language.Haskell.Codo
+>
+> foo :: (Comonad c, Num a) => c a -> a
+> foo = [codo| x => extract x + 1 |]
View
@@ -0,0 +1,17 @@
+> {-# LANGUAGE TemplateHaskell #-}
+> {-# LANGUAGE QuasiQuotes #-}
+> import Control.Comonad
+> import Language.Haskell.Codo
+> import Data.Monoid
+
+> instance Monoid Double where
+> mempty = 0.0
+> mappend = (+)
+
+> differentiate f = ((f 0.001) - f 0) / 0.001
+
+> minima :: (Double -> Double) -> Bool
+> minima = [codo| f => f' <- differentiate f
+> f'' <- differentiate f'
+> (extract f' < 0.001) && (extract f'' > 0) |]
+
@@ -1,7 +1,7 @@
> {-# LANGUAGE TemplateHaskell #-}
> {-# LANGUAGE NoMonomorphismRestriction #-}
-> module Language.Haskell.Codo where
+> module Language.Haskell.Codo(codo) where
> import Text.ParserCombinators.Parsec
> import Text.ParserCombinators.Parsec.Expr

0 comments on commit 35eb7ca

Please sign in to comment.