-
-
Save Lysxia/e6a2f51934483f23cce9925f1d9fc9aa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE DeriveGeneric #-} | |
import Control.Applicative | |
import Test.QuickCheck | |
import GHC.Generics | |
data FirstChoice a = FirstChoice a [a] | |
deriving (Eq, Show, Generic) | |
instance Functor FirstChoice where | |
fmap f (FirstChoice x xs) = FirstChoice (f x) (fmap f xs) | |
instance Applicative FirstChoice where | |
pure x = FirstChoice x [x] | |
FirstChoice f [_] <*> xs = fmap f xs | |
fs <*> FirstChoice x _ = fmap (\f -> f x) fs | |
-- | |
instance Arbitrary a => Arbitrary (FirstChoice a) where | |
arbitrary = FirstChoice <$> arbitrary <*> arbitrary | |
shrink = genericShrink | |
main :: IO () | |
main = do | |
quickCheck (\xs ys zs -> liftA2 (++) (liftA2 (++) xs ys) zs === (liftA2 (++) xs (liftA2 (++) ys zs) :: FirstChoice [Int])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment