Commit 486c945b authored by Bas Lijnse's avatar Bas Lijnse

Merge branch 'lazy-fmap' into 'master'

Make fmap lazy

See merge request !280
parents d1d571dd 47cc0f10
Pipeline #30000 passed with stage
in 3 minutes and 9 seconds
......@@ -179,6 +179,8 @@ instance ArrowApply (Kleisli m) | Monad m
:: ArrowMonad a b = ArrowMonad (a () b)
instance Functor (ArrowMonad a) | Arrow a
where
fmap :: (t -> u) !(ArrowMonad a t) -> ArrowMonad a u | Arrow a
instance pure (ArrowMonad a) | Arrow a
instance <*> (ArrowMonad a) | Arrow a
......
......@@ -105,7 +105,9 @@ instance ArrowApply (->) where
instance ArrowApply (Kleisli m) | Monad m where
app = Kleisli (\(Kleisli f, x) -> f x)
instance Functor (ArrowMonad a) | Arrow a where
instance Functor (ArrowMonad a) | Arrow a
where
fmap :: (t -> u) !(ArrowMonad a t) -> ArrowMonad a u | Arrow a
fmap f (ArrowMonad m) = ArrowMonad (m >>> arr f)
instance pure (ArrowMonad a) | Arrow a
......
......@@ -14,6 +14,8 @@ from Data.Monoid import class Monoid, class Semigroup
:: RWST r w s m a = RWST !(r s -> m (a, s, w))
instance Functor (RWST r w s m) | Monad m & Monoid w
where
fmap :: (a -> b) !(RWST r w s m a) -> RWST r w s m b | Monad m & Monoid w
instance pure (RWST r w s m) | pure m & Monoid w
instance <*> (RWST r w s m) | Monad m & Monoid w
instance Monad (RWST r w s m) | Monad m & Monoid w
......
......@@ -11,8 +11,10 @@ import Control.Monad
import Control.Monad.Trans
import Control.Applicative
instance Functor (RWST r w s m) | Monad m & Monoid w where
fmap f m = liftM f m
instance Functor (RWST r w s m) | Monad m & Monoid w
where
fmap :: (a -> b) !(RWST r w s m a) -> RWST r w s m b | Monad m & Monoid w
fmap f m = liftM f m
instance pure (RWST r w s m) | pure m & Monoid w
where
......
......@@ -23,6 +23,8 @@ local :: u:((.a -> .b) -> v:(.(ReaderT .b .c .d) -> .(ReaderT .a .c .d)))
asks :: (a -> b) -> ReaderT a c b | Monad c
instance Functor (ReaderT r m) | Monad m
where
fmap :: (a -> b) !(ReaderT r m a) -> ReaderT r m b | Monad m
instance pure (ReaderT r m) | Monad m
instance <*> (ReaderT r m) | Monad m
instance Monad (ReaderT r m) | Monad m
......
......@@ -6,8 +6,10 @@ import Control.Applicative
from StdFunc import o, const
import Control.Monad.Trans
instance Functor (ReaderT r m) | Monad m where
fmap f m = liftM f m
instance Functor (ReaderT r m) | Monad m
where
fmap :: (a -> b) !(ReaderT r m a) -> ReaderT r m b | Monad m
fmap f m = liftM f m
instance pure (ReaderT r m) | Monad m
where
......
......@@ -12,6 +12,8 @@ from Data.Functor.Identity import :: Identity
:: Writer w a :== WriterT w Identity a
instance Functor (WriterT w m) | Monad m & Monoid w
where
fmap :: (a -> b) !(WriterT w m a) -> WriterT w m b | Monad m & Monoid w
instance pure (WriterT w m) | pure m & Monoid w
instance <*> (WriterT w m) | Monad m & Monoid w
instance Monad (WriterT w m) | Monad m & Monoid w
......
......@@ -8,8 +8,10 @@ import Control.Monad.Trans
from StdFunc import o
from StdTuple import fst, snd
instance Functor (WriterT w m) | Monad m & Monoid w where
fmap f m = liftM f m
instance Functor (WriterT w m) | Monad m & Monoid w
where
fmap :: (a -> b) !(WriterT w m a) -> WriterT w m b | Monad m & Monoid w
fmap f m = liftM f m
instance pure (WriterT w m) | pure m & Monoid w
where
......
......@@ -32,7 +32,8 @@ appendArr :: !(arr a) !(arr a) -> arr a | Array arr a
instance +++ (arr a) | Array arr a
instance Functor {}, {!}
instance Functor {} where fmap :: (a -> b) !{a} -> {b}
instance Functor {!} where fmap :: (a -> b) !{!a} -> {!b}
instance pure {}
instance pure {!} where pure :: !a -> {!a}
instance <*> {}, {!}
......
......@@ -114,8 +114,15 @@ appendArr l r
instance +++ (arr a) | Array arr a where
(+++) l r = appendArr l r
instance Functor {} where fmap f arr = {f a\\a<-:arr}
instance Functor {!} where fmap f arr = {f a\\a<-:arr}
instance Functor {}
where
fmap :: (a -> b) !{a} -> !{b}
fmap f arr = {f a\\a<-:arr}
instance Functor {!}
where
fmap :: (a -> b) !{!a} -> !{!b}
fmap f arr = {f a\\a<-:arr}
instance pure {}
where
......
......@@ -20,7 +20,7 @@ from Data.GenEq import generic gEq
*/
:: MaybeErrorString a :== MaybeError String a
instance Functor (MaybeError a)
instance Functor (MaybeError e) where fmap :: (a -> b) !(MaybeError e a) -> MaybeError e b
instance pure (MaybeError a)
instance <*> (MaybeError a)
instance Monad (MaybeError a)
......
......@@ -7,6 +7,7 @@ import Control.Applicative
instance Functor (MaybeError a)
where
fmap :: (a -> b) !(MaybeError e a) -> MaybeError e b
fmap f (Ok x) = Ok (f x)
fmap f (Error x) = Error x
......
......@@ -2,16 +2,16 @@ definition module Data.Functor
class Functor f
where
fmap :: (a -> b) !(f a) -> f b
fmap :: (a -> b) (f a) -> f b
(<$>) infixl 4 :: (a -> b) !(f a) -> f b | Functor f
(<$>) f fa :== fmap f fa
(<$) infixl 4 :: a !(f b) -> f a | Functor f
(<$) infixl 4 :: a (f b) -> f a | Functor f
(<$) x fa :== fmap (\_ -> x) fa
($>) infixl 4 :: !(f b) a -> f a | Functor f
($>) infixl 4 :: (f b) a -> f a | Functor f
($>) fa x :== x <$ fa
void :: !(f a) -> f () | Functor f
void :: (f a) -> f () | Functor f
void x :== () <$ x
......@@ -8,7 +8,7 @@ from Control.Applicative import class pure, class <*>, class Applicative
runIdentity :: (Identity .a) -> .a
instance Functor Identity
instance Functor Identity where fmap :: (a -> b) !(Identity a) -> Identity b
instance pure Identity
instance <*> Identity
instance Monad Identity
......@@ -9,8 +9,10 @@ import Control.Monad
runIdentity :: (Identity .a) -> .a
runIdentity (Identity a) = a
instance Functor Identity where
fmap f (Identity m) = Identity (f m)
instance Functor Identity
where
fmap :: (a -> b) !(Identity a) -> Identity b
fmap f (Identity m) = Identity (f m)
instance pure Identity
where
......
......@@ -12,6 +12,7 @@ definition module Data.IntMap.Base
* @property-test-with a = ()
*/
from StdOverloaded import class ==
from Data.Functor import class Functor
from Data.Maybe import :: Maybe
// A map of integers to values @a@.
......@@ -29,6 +30,8 @@ from Data.Maybe import :: Maybe
instance == (IntMap a) | == a
instance Functor IntMap where fmap :: (a -> b) !(IntMap a) -> IntMap b
equal :: !(IntMap a) !(IntMap a) -> Bool | == a
bin :: !Prefix !Mask !(IntMap a) !(IntMap a) -> IntMap a
......
......@@ -6,7 +6,6 @@ import Control.Applicative
import Control.Monad
import Data.Either
import Data.Functor
import Data.Functor
import Data.Maybe
import Data.Monoid
......@@ -17,6 +16,11 @@ instance Semigroup (IntMap a) where
instance Monoid (IntMap a) where
mempty = empty
instance Functor IntMap
where
fmap :: (a -> b) !(IntMap a) -> IntMap b
fmap f xs = map f xs
//instance Foldable.Foldable IntMap where
//fold = go
//where go Nil = mempty
......@@ -1532,12 +1536,6 @@ nequal (Tip kx x) (Tip ky y)
nequal Nil Nil = False
nequal _ _ = True
//instance < (IntMap a) | < a where
//(<) m1 m2 = toList m1 < toList m2
instance Functor IntMap where
fmap f xs = map f xs
link :: !Prefix !(IntMap a) !Prefix !(IntMap a) -> IntMap a
link p1 t1 p2 t2
| zero p1 m = Bin p m t1 t2
......
......@@ -15,11 +15,11 @@ from StdOverloaded import class ==, class <
from StdBool import not
from StdFunc import id
from Text.GenJSON import generic JSONEncode, generic JSONDecode, :: JSONNode
from Data.Functor import class Functor
from Data.GenEq import generic gEq
from Data.Monoid import class Monoid, class Semigroup
from StdList import foldr
from Data.Functor import class Functor (..)
from Data.IntMap.Base import :: IntMap (..), :: Mask, :: Prefix, minViewWithKey, maxViewWithKey, empty, lookup, instance == (IntMap a), equal
from Data.IntMap.Base import :: IntMap (..), :: Mask, :: Prefix, minViewWithKey, maxViewWithKey, empty, lookup, instance == (IntMap a), instance Functor IntMap, equal
null :: !(IntMap a) -> Bool
......@@ -131,8 +131,6 @@ union :: !(IntMap a) !(IntMap a) -> IntMap a
unions :: ![IntMap a] -> IntMap a
instance Functor IntMap
// | /O(n)/. Map a function over all values in the map.
//
// > map (++ "x") (fromList [(5,"a"), (3,"b")]) == fromList [(3, "bx"), (5, "ax")]
......
......@@ -728,11 +728,6 @@ fromAscListWithKey f [x0 : xs0] = fromDistinctAscList (combineEq x0 xs0)
//:: Stack a = Push !Prefix !(IntMap a) !(Stack a) | Nada
instance Functor IntMap where
fmap _ Nil = Nil
fmap f (Tip n x) = Tip n (f x)
fmap f (Bin p m l r) = Bin p m (fmap f l) (fmap f r)
mapSt :: !(a *st -> *(b, *st)) !.(IntMap a) !*st -> *(!IntMap b, !*st)
mapSt _ Nil st = (Nil, st)
mapSt f (Tip n x) st
......
......@@ -20,9 +20,9 @@ subRForest :: (RTree a) -> RForest a
:: RForest a :== [RTree a]
instance Functor RTree
instance Functor RTree where fmap :: (a -> b) !(RTree a) -> RTree b
fmapRTree :: (a -> b) (RTree a) -> RTree b
fmapRTree :: (a -> b) !(RTree a) -> RTree b
instance pure RTree
instance <*> RTree
......
......@@ -14,10 +14,12 @@ rootLabel (RNode x _) = x
subRForest :: (RTree a) -> RForest a
subRForest (RNode _ xs) = xs
instance Functor RTree where
fmap f t = fmapRTree f t
instance Functor RTree
where
fmap :: (a -> b) !(RTree a) -> RTree b
fmap f t = fmapRTree f t
fmapRTree :: (a -> b) (RTree a) -> RTree b
fmapRTree :: (a -> b) !(RTree a) -> RTree b
fmapRTree f (RNode x ts) = RNode (f x) (map (fmapRTree f) ts)
instance pure RTree
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment