
13 Mar
2009
13 Mar
'09
12:09 a.m.
2009/3/12 Peter Verswyvelen
I think. Or is it defined in some other package?
Note that you can get an Applicative instance for "free" by using "WrapMonad" in Control.Applicative. For example, just today I was writing a quickcheck Arbitrary instance, and the Gen monad doesn't have an Applicative instance. No problem:
instance Gen MyDataType where arbitrary = MyDataConstructor <$> arbitrary <*> arbitrary
becomes
instance Gen MyDataType where arbitrary = unWrapMonad (MyDataConstructor <$> WrapMonad arbitrary <*> WrapMonad arbitrary)
This works because every monad induces an Applicative instance in a way I've ingested just enough wine to forget. =] Denis