Skip to content

Commit

Permalink
Getting examples working with GHC generics.
Browse files Browse the repository at this point in the history
  • Loading branch information
leepike committed May 16, 2012
1 parent 4e68d1e commit 66f87cd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 36 deletions.
1 change: 1 addition & 0 deletions TODO.md
Expand Up @@ -26,6 +26,7 @@ TODO


* Make SubT from Forest into Tree(?) More natural and allows to index the head. * Make SubT from Forest into Tree(?) More natural and allows to index the head.



Won't Do / Can't Do Won't Do / Can't Do
----------------------------------------------- -----------------------------------------------
* Use shrink instances as default for base types. * Use shrink instances as default for base types.
Expand Down
26 changes: 7 additions & 19 deletions examples/LambdaCalc.hs
@@ -1,4 +1,5 @@
{-# LANGUAGE DeriveDataTypeable #-} {-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}


-- Copied from <http://augustss.blogspot.com/2007/10/simpler-easier-in-recent-paper-simply.html> -- Copied from <http://augustss.blogspot.com/2007/10/simpler-easier-in-recent-paper-simply.html>


Expand All @@ -8,6 +9,8 @@ import Data.List
import Data.Tree import Data.Tree
import Data.Data import Data.Data
import Control.Monad import Control.Monad
import GHC.Generics

import Test.QuickCheck import Test.QuickCheck


import Test.SmartCheck import Test.SmartCheck
Expand All @@ -18,7 +21,7 @@ data Expr
= Var Sym = Var Sym
| App Expr Expr | App Expr Expr
| Lam Sym Expr | Lam Sym Expr
deriving (Eq, Read, Show, Data, Typeable) deriving (Eq, Read, Show, Data, Typeable, Generic)


freeVars :: Expr -> [Sym] freeVars :: Expr -> [Sym]
freeVars (Var s) = [s] freeVars (Var s) = [s]
Expand All @@ -32,7 +35,6 @@ subst v x b = sub b
sub (Lam i e) = sub (Lam i e) =
if v == i then if v == i then
Lam i e Lam i e
-- Wrong!
else if i `elem` fvx then else if i `elem` fvx then
let i' = cloneSym e i let i' = cloneSym e i
e' = substVar i i' e e' = substVar i i' e
Expand Down Expand Up @@ -76,27 +78,13 @@ test0 = betaEq (app2 plus one two) three


--------------------------------------------------------------------------------- ---------------------------------------------------------------------------------


instance SubTypes Expr where instance SubTypes Expr
subTypes (Var _) = [] instance SubTypes Pr
subTypes (App e0 e1) = [ Node (subT e0) (subTypes e0)
, Node (subT e1) (subTypes e1)
]
subTypes (Lam v e) = [ Node (subT v) []
, Node (subT e) (subTypes e)
]

-- instance (SubTypes a, Data a, SubTypes b, Data b) => SubTypes (a,b) where
-- subTypes (a,b) = subTypes a ++ subTypes b

instance SubTypes Pr where
subTypes (Pr a b) = [ Node (subT a) (subTypes a)
, Node (subT b) (subTypes b)
]


--------------------------------------------------------------------------------- ---------------------------------------------------------------------------------


data Pr = Pr Expr Expr data Pr = Pr Expr Expr
deriving (Read, Show, Data, Typeable) deriving (Read, Show, Data, Typeable, Generic)


instance Arbitrary Expr where instance Arbitrary Expr where
arbitrary = sized mkE arbitrary = sized mkE
Expand Down
3 changes: 2 additions & 1 deletion smartcheck.cabal
Expand Up @@ -28,7 +28,8 @@ Library
mtl >= 2.0.1.0, mtl >= 2.0.1.0,
random >= 1.0.1.1, random >= 1.0.1.1,
uniplate >= 1.6.6, uniplate >= 1.6.6,
containers >= 0.4 containers >= 0.4,
ghc-prim


default-language: Haskell2010 default-language: Haskell2010


Expand Down
32 changes: 16 additions & 16 deletions src/Test/SmartCheck/Types.hs
Expand Up @@ -145,32 +145,32 @@ instance (Show a, Data a, Q.Arbitrary a, SubTypes a) => GST (K1 i a) where
--------------------------------------------------------------------------------- ---------------------------------------------------------------------------------


instance SubTypes Bool where instance SubTypes Bool where
subTypes _ = [] subTypes _ = []
baseType _ = True baseType _ = True
allSubTypes = subTypes allSubTypes _ = []
instance SubTypes Int where instance SubTypes Int where
subTypes _ = [] subTypes _ = []
baseType _ = True baseType _ = True
allSubTypes = subTypes allSubTypes _ = []
instance SubTypes Integer where instance SubTypes Integer where
subTypes _ = [] subTypes _ = []
baseType _ = True baseType _ = True
allSubTypes = subTypes allSubTypes _ = []
instance SubTypes Char where instance SubTypes Char where
subTypes _ = [] subTypes _ = []
baseType _ = True baseType _ = True
allSubTypes = subTypes allSubTypes _ = []
instance SubTypes String where instance SubTypes String where
subTypes _ = [] subTypes _ = []
baseType _ = True baseType _ = True
allSubTypes = subTypes allSubTypes _ = []


-- mkSubT :: (Data a, Q.Arbitrary a, Show a) => a -> Forest SubT -- mkSubT :: (Data a, Q.Arbitrary a, Show a) => a -> Forest SubT
-- mkSubT i = [ Node (subT i) [] ] -- mkSubT i = [ Node (subT i) [] ]


instance (Q.Arbitrary a, SubTypes a) => SubTypes [a] where instance (Q.Arbitrary a, SubTypes a) => SubTypes [a] where
subTypes = concatMap subTypes subTypes = concatMap subTypes
baseType _ = False baseType _ = False
allSubTypes = subTypes allSubTypes = concatMap allSubTypes


--------------------------------------------------------------------------------- ---------------------------------------------------------------------------------

0 comments on commit 66f87cd

Please sign in to comment.