Function.hs (4089B)
1 module Lude.Function ( 2 app, 3 ($), 4 rapp, 5 (&), 6 const, 7 flip, 8 on, 9 compose00#, 10 (.#), 11 compose00, 12 -- (.), 13 compose01#, 14 (.*#), 15 compose01, 16 (.*), 17 compose10#, 18 (*.#), 19 compose10, 20 (*.), 21 compose11#, 22 (*.*#), 23 compose11, 24 (*.*), 25 ) where 26 27 import Lude.Haskell 28 29 -- TODO: Generalize some of this? E.g., for CCCs? 30 31 -- TODO: Repr-generic S combinators? 32 33 -------------------------------------------------------------------------------- 34 35 app, ($) :: forall {r :: Repr} (a :: Type# r) {s :: Repr} (b :: Type# s). (a -> b) -> (a -> b) 36 app f = f 37 ($) = app 38 {-# INLINE app #-} 39 {-# INLINE ($) #-} 40 infixl 1 $ 41 42 rapp, (&) :: forall {r :: Repr} (a :: Type# r) {s :: Repr} (b :: Type# s). (Functional# r) => a -> (a -> b) -> b 43 rapp = lam# \x f -> app# f x 44 (&) = rapp 45 {-# INLINE rapp #-} 46 {-# INLINE (&) #-} 47 infixl 0 & 48 49 const 50 :: forall {r :: Repr} (a :: Type# r) {s :: Repr} (b :: Type# s) 51 . (Functional# r, Functional# s) => a -> (b -> a) 52 const = lam2# \x _ -> x 53 {-# INLINE const #-} 54 55 flip 56 :: forall {r :: Repr} (a :: Type# r) {s :: Repr} (b :: Type# s) {t :: Repr} (c :: Type# t) 57 . (Functional# r, Functional# s) => (b -> a -> c) -> (a -> b -> c) 58 flip f = lam2# \y x -> app2# f x y 59 {-# INLINE flip #-} 60 61 on 62 :: forall {r :: Repr} (a :: Type# r) {s :: Repr} (b :: Type# s) {t :: Repr} (c :: Type# t) 63 . (Functional# r, Functional# s) => (b -> b -> c) -> (a -> b) -> (a -> a -> c) 64 on f g = lam2# \x y -> app2# f (app# g x) (app# g y) 65 {-# INLINE on #-} 66 67 -------------------------------------------------------------------------------- 68 -- Composition 69 70 compose00#, 71 (.#) 72 :: forall {r0 :: Repr} (a0 :: Type# r0) {s :: Repr} (b :: Type# s) {t :: Repr} (c :: Type# t) 73 . (Functional# r0, Functional# s) => (b -> c) -> (a0 -> b) -> (a0 -> c) 74 compose00# = composeFunction 75 (.#) = compose00# 76 {-# INLINE compose00# #-} 77 {-# INLINE (.#) #-} 78 infixr 9 .# 79 80 compose00 81 :: forall (a0 :: Type) (b :: Type) (c :: Type) 82 . (b -> c) -> (a0 -> b) -> (a0 -> c) 83 compose00 = compose00# 84 {-# INLINE compose00 #-} 85 86 compose01#, 87 (.*#) 88 :: forall {r0 :: Repr} (a0 :: Type# r0) {r1 :: Repr} (a1 :: Type# r1) {s :: Repr} (b :: Type# s) {t :: Repr} (c :: Type# t) 89 . (Functional# r0, Functional# r1, Functional# s) => (b -> c) -> (a0 -> a1 -> b) -> (a0 -> a1 -> c) 90 compose01# g f = lam# \x0 -> compose00# g (f $# x0) 91 (.*#) = compose01# 92 {-# INLINE compose01# #-} 93 {-# INLINE (.*#) #-} 94 infixr 9 .*# 95 96 compose01, 97 (.*) 98 :: forall (a0 :: Type) (a1 :: Type) (b :: Type) (c :: Type) 99 . (b -> c) -> (a0 -> a1 -> b) -> (a0 -> a1 -> c) 100 compose01 = compose01# 101 (.*) = compose01 102 {-# INLINE compose01 #-} 103 {-# INLINE (.*) #-} 104 infixr 9 .* 105 106 compose10#, 107 (*.#) 108 :: forall {r0 :: Repr} (a0 :: Type# r0) {s0 :: Repr} (b0 :: Type# s0) {s :: Repr} (b :: Type# s) {t :: Repr} (c :: Type# t) 109 . (Functional# r0, Functional# s0, Functional# s) => (b0 -> b -> c) -> (a0 -> b) -> (b0 -> a0 -> c) 110 compose10# g f = lam# \y -> compose00# (g $# y) f 111 (*.#) = compose10# 112 {-# INLINE compose10# #-} 113 {-# INLINE (*.#) #-} 114 infixr 9 *.# 115 116 compose10, 117 (*.) 118 :: forall (a0 :: Type) (b0 :: Type) (b :: Type) (c :: Type) 119 . (b0 -> b -> c) -> (a0 -> b) -> (b0 -> a0 -> c) 120 compose10 = compose10# 121 (*.) = compose10 122 {-# INLINE compose10 #-} 123 {-# INLINE (*.) #-} 124 infixr 9 *. 125 126 compose11#, 127 (*.*#) 128 :: forall {r0 :: Repr} (a0 :: Type# r0) {r1 :: Repr} (a1 :: Type# r1) {s0 :: Repr} (b0 :: Type# s0) {s :: Repr} (b :: Type# s) {t :: Repr} (c :: Type# t) 129 . (Functional# r0, Functional# r1, Functional# s0, Functional# s) => (b0 -> b -> c) -> (a0 -> a1 -> b) -> (b0 -> a0 -> a1 -> c) 130 compose11# g f = lam# \y -> compose01# (g $# y) f 131 (*.*#) = compose11# 132 {-# INLINE compose11# #-} 133 {-# INLINE (*.*#) #-} 134 infixr 9 *.*# 135 136 compose11, 137 (*.*) 138 :: forall (a0 :: Type) (a1 :: Type) (b0 :: Type) (b :: Type) (c :: Type) 139 . (b0 -> b -> c) -> (a0 -> a1 -> b) -> (b0 -> a0 -> a1 -> c) 140 compose11 = compose11# 141 (*.*) = compose11 142 {-# INLINE compose11 #-} 143 {-# INLINE (*.*) #-} 144 infixr 9 *.*