Skip to content

Instantly share code, notes, and snippets.

@amitaibu
Created March 27, 2016 18:50
Show Gist options
  • Save amitaibu/4a77b7452db9d7ef016d to your computer and use it in GitHub Desktop.
Save amitaibu/4a77b7452db9d7ef016d to your computer and use it in GitHub Desktop.
-- Page: 689
module Applicatives where
import Control.Applicative
import Data.Monoid
import Test.QuickCheck
import Test.QuickCheck.Checkers
import Test.QuickCheck.Classes
take' :: Int -> List a -> List a
take' = undefined
data List a =
Nil
| Cons a (List a)
deriving (Eq, Show)
newtype ZipList' a =
ZipList' (List a)
deriving (Eq, Show)
instance Functor List where
fmap _ Nil = Nil
fmap f (Cons a a') = Cons (f a) (fmap f a')
instance Applicative List where
pure a = (Cons a Nil)
_ <*> Nil = Nil
Nil <*> _ = Nil
(Cons f fs) <*> (Cons a as) = Cons (f a) (fs <*> as)
instance Eq a => EqProp (ZipList' a) where
xs =-= ys = xs' `eq` ys'
where xs' = let (ZipList' l) = xs
in take' 3000 l
ys' = let (ZipList' l) = ys
in take' 3000 l
instance Functor ZipList' where
fmap f (ZipList' xs) = ZipList' $ fmap f xs
instance Applicative ZipList' where
pure = undefined
(<*>) = undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment