Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1.  upgrade Hackage show to QuickCheck 2 for lambdabot (Mark Wright)
   2. Re:  Re: Enforcing Monad Laws (Brandon S Allbery KF8NH)


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

Message: 1
Date: Fri, 2 Jul 2010 23:49:36 +1000
From: Mark Wright <[email protected]>
Subject: [Haskell-beginners] upgrade Hackage show to QuickCheck 2 for
        lambdabot
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

Hi,

I'm trying to upgrade Hackage show to QuickCheck 2, after
applying the diffs below (which may not be correct, since I am
a beginner), I am left which this error message:

runghc ./Setup.hs build
Preprocessing library show-0.3.4...
Building show-0.3.4...
[4 of 4] Compiling ShowQ            ( ShowQ.hs, dist/build/ShowQ.o )

ShowQ.hs:104:20: Not in scope: `generate'

Compilation exited abnormally with code 1 at Fri Jul  2 23:07:17

The error occurs in this method:

tests :: Gen Result -> StdGen -> Int -> Int -> [[String]] -> IO String
tests gen rnd0 ntest nfail stamps
  | ntest == 500  = done "OK, passed" ntest stamps
  | nfail == 1000 = done "Arguments exhausted after" ntest stamps
  | otherwise = case ok result of
       Nothing    -> tests gen rnd1 ntest (nfail+1) stamps
       Just True  -> tests gen rnd1 (ntest+1) nfail (stamp result:stamps)
       Just False -> return $ "Falsifiable, after "
                               ++ show ntest
                               ++ " tests:\n"
                               ++ reason result
   where
      result      = generate (((+ 3) . (`div` 2)) ntest) rnd2 gen
      (rnd1,rnd2) = split rnd0

The QuickCheck 1 generate method is near the bottom this page:

http://hackage.haskell.org/packages/archive/QuickCheck/1.2.0.0/doc/html/Test-QuickCheck.html

but I can not find generate in QuickCheck 2.  I am wondering if
you have any ideas on how to fix it?

I'm trying to package lambdabot on Solaris.  I have already packaged
the Haskell Platform and about 90 packages, they are in:

http://pkgbuild.sourceforge.net/spec-files-extra/

Thanks very much, Mark

here are the diffs:

goanna% diff -wc show-0.3.4-orig/ShowQ.hs show-0.3.4/ShowQ.hs 
*** show-0.3.4-orig/ShowQ.hs    Wed Jan 20 11:24:11 2010
--- show-0.3.4/ShowQ.hs Fri Jul  2 23:07:13 2010
***************
*** 12,22 ****
--- 12,25 ----
  
  import qualified Test.SmallCheck (smallCheck, Testable)
  import Test.QuickCheck
+ import Test.QuickCheck.Arbitrary
  import Data.Char
  import Data.List
  import Data.Word
  import Data.Int
  import System.Random
+ import Control.Exception (evaluate)
+ import Test.QuickCheck.Property (ok, stamp)
  
  type T = [Int]
  type I = Int
***************
*** 23,36 ****
--- 26,45 ----
  
  instance Arbitrary Char where
      arbitrary     = choose (minBound, maxBound)
+     
+ instance CoArbitrary Char where
      coarbitrary c = variant (ord c `rem` 4)
  
  instance Arbitrary Word8 where
      arbitrary = choose (minBound, maxBound)
+     
+ instance CoArbitrary Word8 where
      coarbitrary c = variant (fromIntegral ((fromIntegral c) `rem` 4))
  
  instance Arbitrary Ordering where
      arbitrary     = elements [LT,EQ,GT]
+ 
+ instance CoArbitrary Ordering where
      coarbitrary LT = variant 1
      coarbitrary EQ = variant 2
      coarbitrary GT = variant 0
***************
*** 37,42 ****
--- 46,53 ----
  
  instance Arbitrary Int64 where
    arbitrary     = sized $ \n -> choose (-fromIntegral n,fromIntegral n)
+   
+ instance CoArbitrary Int64 where
    coarbitrary n = variant (fromIntegral (if n >= 0 then 2*n else 2*(-n) + 1))
  
  instance (Integral a, Arbitrary a) => Arbitrary (Ratio a) where
***************
*** 48,53 ****
--- 59,65 ----
                              else (b % a)
                           else (a % b)
  
+ instance (Integral a, CoArbitrary a) => CoArbitrary (Ratio a) where
    coarbitrary m = variant (fromIntegral $ if n >= 0 then 2*n else 2*(-n) + 1)
      where n = numerator m
  
***************
*** 87,93 ****
         Just False -> return $ "Falsifiable, after "
                                 ++ show ntest
                                 ++ " tests:\n"
!                                ++ unlines (arguments result)
     where
        result      = generate (((+ 3) . (`div` 2)) ntest) rnd2 gen
        (rnd1,rnd2) = split rnd0
--- 99,105 ----
         Just False -> return $ "Falsifiable, after "
                                 ++ show ntest
                                 ++ " tests:\n"
!                                ++ reason result
     where
        result      = generate (((+ 3) . (`div` 2)) ntest) rnd2 gen
        (rnd1,rnd2) = split rnd0
goanna% 



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

Message: 2
Date: Fri, 02 Jul 2010 11:12:54 -0400
From: Brandon S Allbery KF8NH <[email protected]>
Subject: Re: [Haskell-beginners] Re: Enforcing Monad Laws
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 7/2/10 04:04 , Heinrich Apfelmus wrote:
> Jorden M wrote:
>> C++ `Concepts', which almost made it into the C++0x standard, are
>> roughly similar to Haskell type classes. The proposal for concepts in
>> C++ had a feature called axioms, which allow the programmer to specify
>> semantics on the functions the concept contains. This allows for
>> enforcing things such as the Monad Laws, as well as letting the
>> compiler make certain optimizations it may not have been able to make
>> without axiomatic guarantees.
> 
> I have a hard time imagining that axioms are being used to prove properties
> about programs in a language such as C++... :) Any pointers?

I just took a look at it, and Concepts look to me like Haskell
contexts/constraints; an example is:

> concept LessThanComparable<typename T> {
>   bool operator<(const T& x, const T& y);
> }
> 
> template<typename T>
> requires LessThanComparable<T>
> const T& min(const T& x, const T& y) {
>   return x < y? x : y;
> }

which is obviously just an Ord costraint on min().

(My initial thought before looking at this was that it was programming by
contract, or possibly just making invariants explicit; the latter wouldn't
actually prove anything, though.)

- -- 
brandon s. allbery     [linux,solaris,freebsd,perl]      [email protected]
system administrator  [openafs,heimdal,too many hats]  [email protected]
electrical and computer engineering, carnegie mellon university      KF8NH
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.10 (Darwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkwuAfYACgkQIn7hlCsL25URBQCeOsh3m3jfmifLeG8kzLC6Df74
PU4AoJwho/HN9IClcBw6RTN6kzVxRvX1
=B0SX
-----END PGP SIGNATURE-----


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

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 25, Issue 6
****************************************

Reply via email to