From c91a10869980894de7d6daac875af412907016c6 Mon Sep 17 00:00:00 2001 From: Steven Dee Date: Sun, 20 Oct 2013 20:53:19 -0400 Subject: [PATCH] More applicative --- test.hs | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/test.hs b/test.hs index adf956b..65d3976 100644 --- a/test.hs +++ b/test.hs @@ -1,4 +1,4 @@ -import Control.Monad +import Control.Applicative import Nock5K.Parse import Nock5K.Spec import Test.QuickCheck @@ -10,22 +10,19 @@ main = mapM_ (\(s,a) -> printf "%-25s: " s >> a) tests instance Arbitrary Noun where arbitrary = do coin <- arbitrary if coin - then liftM (Atom . abs) arbitrary - else do a <- arbitrary - b <- arbitrary - return $ a :- b + then (Atom . abs) <$> arbitrary + else (:-) <$> arbitrary <*> arbitrary -prop_parse_show n = n == ps n - where ps n = case parse noun "" (show n) of - Left e -> error "parse" - Right n -> n +parsenoun n = case parse noun "" n of + Left e -> error "parse" + Right n -> n + +prop_parse_show n = n == (parsenoun . show) n prop_dec a' = nock (Atom (a + 1) :- dec) == Atom a where ds = "[8 [1 0] 8 [1 6 [5 [0 7] 4 0 6] [0 6] 9 2 [0 2] [4 0 6] 0 7] 9 2 0 1]" - dec = case parse noun "" ds of - Left e -> error "parse" - Right n -> n + dec = parsenoun ds a = abs a' prop_6_is_if a' b' = nock (ifs $ Atom 0) == Atom (a + 1) && nock (ifs $ Atom 1) == Atom b