Guest User

Untitled

a guest
Oct 22nd, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. module Lib where
  2.  
  3. import Test.QuickCheck
  4. import Test.QuickCheck.Checkers
  5.  
  6.  
  7. data List a = Nil
  8. | Cons a (List a)
  9. deriving(Eq, Show)
  10.  
  11.  
  12. instance Functor List where
  13. fmap _ Nil = Nil
  14. fmap f (Cons a al) = Cons (f a) (fmap f al)
  15.  
  16. instance (Arbitrary a) => Arbitrary (List a) where
  17. arbitrary = do
  18. a <- arbitrary
  19. b <- arbitrary
  20. frequency [ (1, return Nil), (1, return (Cons a b))]
  21.  
  22. instance Eq a => EqProp (List a) where (=-=) = eq
  23.  
  24. instance Applicative List where
  25. pure x = Cons x Nil
  26. _ <*> Nil = Nil
  27. Nil <*> _ = Nil
  28. Cons f fs <*> Cons a as = append (Cons (f a) (fmap f as)) (fs <*> Cons a as)
  29.  
  30. instance Monad List where
  31. return = pure
  32. (>>=) (Cons a al) f = (f a ) (>>= al f)
Add Comment
Please, Sign In to add comment