Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Lib where
- import Test.QuickCheck
- import Test.QuickCheck.Checkers
- data List a = Nil
- | Cons a (List a)
- deriving(Eq, Show)
- instance Functor List where
- fmap _ Nil = Nil
- fmap f (Cons a al) = Cons (f a) (fmap f al)
- instance (Arbitrary a) => Arbitrary (List a) where
- arbitrary = do
- a <- arbitrary
- b <- arbitrary
- frequency [ (1, return Nil), (1, return (Cons a b))]
- instance Eq a => EqProp (List a) where (=-=) = eq
- instance Applicative List where
- pure x = Cons x Nil
- _ <*> Nil = Nil
- Nil <*> _ = Nil
- Cons f fs <*> Cons a as = append (Cons (f a) (fmap f as)) (fs <*> Cons a as)
- instance Monad List where
- return = pure
- (>>=) (Cons a al) f = (f a ) (>>= al f)
Add Comment
Please, Sign In to add comment