Avoid creating unnecessary join points in Stream.replicate
[darcs-mirrors/vector.git] / Data / Vector / Fusion / Util.hs
1 -- |
2 -- Module : Data.Vector.Fusion.Util
3 -- Copyright : (c) Roman Leshchinskiy 2009
4 -- License : BSD-style
5 --
6 -- Maintainer : Roman Leshchinskiy <rl@cse.unsw.edu.au>
7 -- Stability : experimental
8 -- Portability : portable
9 --
10 -- Fusion-related utility types
11 --
12
13 module Data.Vector.Fusion.Util (
14 Id(..), Box(..),
15
16 delay_inline
17 ) where
18
19 -- | Identity monad
20 newtype Id a = Id { unId :: a }
21
22 instance Functor Id where
23 fmap f (Id x) = Id (f x)
24
25 instance Monad Id where
26 return = Id
27 Id x >>= f = f x
28
29 -- | Box monad
30 data Box a = Box { unBox :: a }
31
32 instance Functor Box where
33 fmap f (Box x) = Box (f x)
34
35 instance Monad Box where
36 return = Box
37 Box x >>= f = f x
38
39 -- | Delay inlining a function until late in the game (simplifier phase 0).
40 delay_inline :: (a -> b) -> a -> b
41 {-# INLINE [0] delay_inline #-}
42 delay_inline f = f
43
44