1. Patrick Bahr
  2. compdata

Commits

Patrick Bahr  committed 7430047

fixed warnings about missing instances for Applicative

  • Participants
  • Parent commits 499c332
  • Branches default

Comments (0)

Files changed (4)

File src/Data/Comp/MultiParam/FreshM.hs

View file
     ) where
 
 import Control.Monad.Reader
+import Control.Applicative
 
 -- |Monad for generating fresh (abstract) names.
 newtype FreshM a = FreshM{unFreshM :: Reader Int a}
-    deriving Monad
+    deriving (Monad, Functor, Applicative)
 
 -- |Abstract notion of a name (the constructor is hidden).
 newtype Name i = Name Int
 
 -- |Evaluate a computation that uses fresh names.
 evalFreshM :: FreshM a -> a
-evalFreshM (FreshM m) = runReader m 0
+evalFreshM (FreshM m) = runReader m 0

File src/Data/Comp/Param/FreshM.hs

View file
     ) where
 
 import Control.Monad.Reader
+import Control.Applicative
 
 -- |Monad for generating fresh (abstract) names.
 newtype FreshM a = FreshM{unFreshM :: Reader Int a}
-    deriving Monad
+    deriving (Monad, Functor, Applicative)
 
 -- |Abstract notion of a name (the constructor is hidden).
 newtype Name = Name Int
 
 -- |Evaluate a computation that uses fresh names.
 evalFreshM :: FreshM a -> a
-evalFreshM (FreshM m) = runReader m 0
+evalFreshM (FreshM m) = runReader m 0

File src/Data/Comp/Sum.hs

View file
 substHoles' :: (Functor f, Functor g, f :<: g, Ord v) => Cxt h' f v -> Map v (Cxt h g a) -> Cxt h g a
 substHoles' c m = substHoles c (fromJust . (`Map.lookup`  m))
 
-instance (Functor f) => Monad (Context f) where
-    return = Hole
-    (>>=) = substHoles
-
 
 instance (Show (f a), Show (g a)) => Show ((f :+: g) a) where
     show (Inl v) = show v
 instance (Eq (f a), Eq (g a)) => Eq ((f :+: g) a) where
     (Inl x) == (Inl y) = x == y
     (Inr x) == (Inr y) = x == y                   
-    _ == _ = False
+    _ == _ = False

File src/Data/Comp/Term.hs

View file
-{-# LANGUAGE EmptyDataDecls, GADTs, KindSignatures, Rank2Types #-}
+{-# LANGUAGE EmptyDataDecls, GADTs, KindSignatures, Rank2Types, TypeSynonymInstances, FlexibleInstances #-}
 --------------------------------------------------------------------------------
 -- |
 -- Module      :  Data.Comp.Term
         where run (Hole v) = Hole (f v)
               run (Term t) = Term (fmap run t)
 
+instance Functor f => Applicative (Context f) where
+    pure = Hole
+    (<*>) = ap
+
+instance (Functor f) => Monad (Context f) where
+    return = Hole
+    m >>= f = run m
+        where run (Hole v) = f v
+              run (Term t) = Term (fmap run t)
+
 instance (Foldable f) => Foldable (Cxt h f) where
     foldr op c a = run a c
         where run (Hole a) e = a `op` e
 
 unTerm :: Cxt NoHole f a -> f (Cxt NoHole f a)
 {-# INLINE unTerm #-}
-unTerm (Term t) = t
+unTerm (Term t) = t