Reputation: 43
I'm having trouble writing an instance of Arbitrary for my data type. Which is the following:
data FavoriteList a = FL [(a, Bool)] deriving Eq
This is what I have:
instance Arbitrary a => Arbitrary(FavoriteList a) where
arbitrary = oneof [liftM FavoriteList arbitrary]
But I'm getting the following error:
Not in scope: data constructor 'FavoriteList'
I'm probably not understanding something about types and constructors I think...Can someone help me out?
Upvotes: 0
Views: 117
Reputation: 15605
You're attempting to use the type-level term FavoriteList
at the value-level. FL
is the value-level term that constructs a value of type FavoriteList a
for whatever a
you choose. FL <$> arbitrary
should be sufficient, or equivalently fmap FL arbitrary
or liftM FL arbitrary
. For a more thorough explanation of Haskell's type- and value-level languages, see this excellent answer by Conor McBride.
Upvotes: 3