documentation
authorTomáš Musil <tomik.musil@gmail.com>
Wed, 3 Dec 2014 23:41:22 +0000 (00:41 +0100)
committerTomáš Musil <tomik.musil@gmail.com>
Wed, 3 Dec 2014 23:41:22 +0000 (00:41 +0100)
fp.cabal
src/Lambda.hs

index 77325ab..789b94c 100644 (file)
--- a/fp.cabal
+++ b/fp.cabal
@@ -15,6 +15,15 @@ build-type:          Simple
 -- extra-source-files:  
 cabal-version:       >=1.10
 
+library 
+  exposed-modules: Lambda
+  build-depends:       base >=4.7 && <4.8
+                     , text >=1.2 && <1.3
+                     , attoparsec >=0.12 && <0.13
+                     , containers
+  hs-source-dirs:      src
+  default-language:    Haskell2010
+
 executable fp
   main-is:             Main.hs
   other-modules:       Lambda
index f54a100..c570199 100644 (file)
@@ -1,19 +1,32 @@
 {-# OPTIONS_GHC -fno-warn-unused-do-bind #-}
 {-# LANGUAGE PatternSynonyms #-}
 
-module Lambda where
+-- |
+-- Module      :  Lambda
+-- Copyright   :  Tomáš Musil 2014
+-- License     :  BSD-3
+--
+-- Maintainer  :  tomik.musil@gmail.com
+-- Stability   :  experimental
+--
+-- This is a toy λ-calculus implementation.
+
+module Lambda 
+  ( -- * Types
+    VarName
+  , Term(..)
+    -- * Parsing terms
+  , parseTerm
+  , tRead
+    -- * Reduction
+  , reduce
+  ) where
+  
 
 import Data.Text as T
 import Data.Attoparsec.Text
 import Control.Applicative
 
-type VarName = String
-data Term = Var VarName | Lambda VarName Term | App Term Term deriving (Eq)
-
-pattern RedEx x t s = App (Lambda x t) s
-pattern AppApp a b c = App a (App b c)
-pattern EmLambda x y t = Lambda x (Lambda y t)
-
 -- $setup
 -- >>> import Test.QuickCheck
 -- >>> import Control.Applicative
@@ -21,12 +34,18 @@ pattern EmLambda x y t = Lambda x (Lambda y t)
 -- >>> let aTerm n = oneof [pure (Var "x"), liftA (Lambda "x") $ aTerm (n - 1), liftA2 App (aTerm (n `div` 2)) (aTerm (n `div` 2))] 
 -- >>> instance Arbitrary Term where arbitrary = sized aTerm
 
--- | Read and show λ-terms
---
---   >>> print $ Lambda "x" (Var "x")
---   (λx.x)
---
---   prop> t == tRead (show (t :: Term))
+type VarName = String
+
+-- | 
+-- >>> print $ Lambda "x" (Var "x")
+-- (λx.x)
+
+data Term = Var VarName | Lambda VarName Term | App Term Term deriving (Eq)
+
+-- pattern RedEx x t s = App (Lambda x t) s
+pattern AppApp a b c = App a (App b c)
+pattern EmLambda x y t = Lambda x (Lambda y t)
+
 
 instance Show Term where
   show (Var x) = x
@@ -38,7 +57,9 @@ instance Show Term where
 braced :: Term -> String
 braced t = "(" ++ show t ++ ")"
 
---instance Read Term where
+-- |
+-- prop> t == tRead (show (t :: Term))
+
 tRead :: String -> Term
 tRead s = case parseOnly (parseTerm <* endOfInput) (T.pack s) of
     (Right t) -> t