-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstant.hs
More file actions
36 lines (29 loc) · 1.03 KB
/
constant.hs
File metadata and controls
36 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Data.Monoid
import Test.QuickCheck
import Test.QuickCheck.Checkers
import Test.QuickCheck.Classes
newtype Constant a b = Constant { getConstant :: a }
deriving (Eq, Ord, Show)
instance Functor (Constant a) where
fmap _ (Constant a) = Constant a
instance forall a . Monoid a => Applicative (Constant a) where
pure :: b -> Constant a b
pure _ = Constant mempty -- pure is trying to give us b
-- a -> f a ... is the last type b
(<*>) :: Constant a (x -> b)
-> Constant a x
-> Constant a b
(<*>) (Constant a) (Constant a')= Constant (a `mappend`a')
instance Arbitrary a => Arbitrary (Constant a b) where
arbitrary = do
a <- arbitrary
return (Constant a)
instance Eq a => EqProp (Constant a b) where
(=-=) = eq
main :: IO ()
main = do
let c :: Constant String (String, String, String)
c = Constant "blah"
quickBatch (applicative c)