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