Skip to content

Instantly share code, notes, and snippets.

@scalolli
Created May 4, 2018 05:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scalolli/7ae9757ef587eefbe8274d8ec9fba55c to your computer and use it in GitHub Desktop.
Save scalolli/7ae9757ef587eefbe8274d8ec9fba55c to your computer and use it in GitHub Desktop.
Writing arbitrary
-- Functor for Company a b c
data Company a b c = DeepBlue a c | Something b deriving (Eq, Show)
instance Functor (Company a b) where
fmap f (DeepBlue a c) = DeepBlue a (f c)
fmap f (Something b) = Something b
instance (Arbitrary a, Arbitrary b, Arbitrary c) => Arbitrary (Company a b c) where
arbitrary = do
x <- arbitrary
y <- arbitrary
z <- arbitrary
elements [DeepBlue x z, Something y]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment