简体   繁体   中英

Not in scope: type constructor or class `GenUnchecked'

I want to set up property based testing using validity , but I'm having trouble getting even this simple example from the documentation to compile:

module PrimeSpec where

import Data.GenValidity
import Data.Validity
import Data.Numbers.Primes
import Test.QuickCheck

newtype Prime = Prime Int

instance Validity Prime where
  validate (Prime n) = declare "The 'Int' is prime." $ isPrime n

instance GenUnchecked Prime where
  genUnchecked = Prime <$> arbitrary

instance GenValid Prime where
  genValid = Prime <$> (oneof [
    pure 2,
    ((\y -> 2 * abs y + 1) <$> arbitrary) `suchThat` isPrime])

The code above fails with:

    Not in scope: type constructor or class `GenUnchecked'
   |
13 | instance GenUnchecked Prime where
   |          ^^^^^^^^^^^^

So I guess I need to import it. I usually do this via hoogle, but GenUnchecked is not listed there . And it's not listed on hackage either. But the hackage documentation for genvalidity has it listed right here in the module Data.Validity (which I imported) and the package genvalidity (which I added to my package.yaml ).

Maybe there are some version conflicts? But I don't know how to check the versions of the installed packages, because I'm fairly new to haskell.

You're looking at the docs of version 0.5.0.0 which is almost 5 years old (you can tell from the URL, the title, and from the style of the page). The latest version of genvalidity is 1.1.0.0 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM