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