@@ -22,9 +22,13 @@ import DataFrame.Internal.Expression (
2222import DataFrame.Internal.Nullable (
2323 BaseType ,
2424 NullCmpResult ,
25- NullableArithOp ( nullArithOp ),
25+ NullLift2Op ( applyNull2 ),
2626 NullableCmpOp (nullCmpOp ),
27+ NumericWidenOp ,
28+ WidenResult ,
29+ widenArithOp ,
2730 )
31+ import DataFrame.Internal.Types (Promote )
2832
2933infix 8 .^^
3034infix 6 .+ , .-
@@ -64,14 +68,17 @@ lit = Lit
6468@col \@Int "x" .+ col \@(Maybe Int) "y" -- :: Expr (Maybe Int)@
6569-}
6670(.+) ::
67- (NullableArithOp a b c , Num (BaseType a )) =>
71+ ( NumericWidenOp (BaseType a ) (BaseType b )
72+ , NullLift2Op a b (Promote (BaseType a ) (BaseType b )) (WidenResult a b )
73+ , Num (Promote (BaseType a ) (BaseType b ))
74+ ) =>
6875 Expr a ->
6976 Expr b ->
70- Expr c
77+ Expr ( WidenResult a b )
7178(.+) =
7279 Binary
7380 ( MkBinaryOp
74- { binaryFn = nullArithOp (+ )
81+ { binaryFn = applyNull2 (widenArithOp (+) )
7582 , binaryName = " nulladd"
7683 , binarySymbol = Just " +"
7784 , binaryCommutative = True
@@ -81,14 +88,17 @@ lit = Lit
8188
8289-- | Nullable-aware subtraction.
8390(.-) ::
84- (NullableArithOp a b c , Num (BaseType a )) =>
91+ ( NumericWidenOp (BaseType a ) (BaseType b )
92+ , NullLift2Op a b (Promote (BaseType a ) (BaseType b )) (WidenResult a b )
93+ , Num (Promote (BaseType a ) (BaseType b ))
94+ ) =>
8595 Expr a ->
8696 Expr b ->
87- Expr c
97+ Expr ( WidenResult a b )
8898(.-) =
8999 Binary
90100 ( MkBinaryOp
91- { binaryFn = nullArithOp (- )
101+ { binaryFn = applyNull2 (widenArithOp (-) )
92102 , binaryName = " nullsub"
93103 , binarySymbol = Just " -"
94104 , binaryCommutative = False
@@ -98,14 +108,17 @@ lit = Lit
98108
99109-- | Nullable-aware multiplication.
100110(.*) ::
101- (NullableArithOp a b c , Num (BaseType a )) =>
111+ ( NumericWidenOp (BaseType a ) (BaseType b )
112+ , NullLift2Op a b (Promote (BaseType a ) (BaseType b )) (WidenResult a b )
113+ , Num (Promote (BaseType a ) (BaseType b ))
114+ ) =>
102115 Expr a ->
103116 Expr b ->
104- Expr c
117+ Expr ( WidenResult a b )
105118(.*) =
106119 Binary
107120 ( MkBinaryOp
108- { binaryFn = nullArithOp (* )
121+ { binaryFn = applyNull2 (widenArithOp (*) )
109122 , binaryName = " nullmul"
110123 , binarySymbol = Just " *"
111124 , binaryCommutative = True
@@ -115,14 +128,17 @@ lit = Lit
115128
116129-- | Nullable-aware division.
117130(./) ::
118- (NullableArithOp a b c , Fractional (BaseType a )) =>
131+ ( NumericWidenOp (BaseType a ) (BaseType b )
132+ , NullLift2Op a b (Promote (BaseType a ) (BaseType b )) (WidenResult a b )
133+ , Fractional (Promote (BaseType a ) (BaseType b ))
134+ ) =>
119135 Expr a ->
120136 Expr b ->
121- Expr c
137+ Expr ( WidenResult a b )
122138(./) =
123139 Binary
124140 ( MkBinaryOp
125- { binaryFn = nullArithOp (/ )
141+ { binaryFn = applyNull2 (widenArithOp (/) )
126142 , binaryName = " nulldiv"
127143 , binarySymbol = Just " /"
128144 , binaryCommutative = False
@@ -258,16 +274,44 @@ lit = Lit
258274 }
259275 )
260276
261- (.^^) :: (Columnable a , Num a ) => Expr a -> Int -> Expr a
262- (.^^) expr i =
277+ (.^^) ::
278+ ( Columnable (BaseType a )
279+ , Columnable (BaseType b )
280+ , Fractional (BaseType a )
281+ , Integral (BaseType b )
282+ , NumericWidenOp (BaseType a ) (BaseType b )
283+ , NullLift2Op a b (BaseType a ) a
284+ , Num (Promote (BaseType a ) (BaseType b ))
285+ ) =>
286+ Expr a -> Expr b -> Expr a
287+ (.^^) =
263288 Binary
264289 ( MkBinaryOp
265- { binaryFn = ( ^)
290+ { binaryFn = applyNull2 (^ ^)
266291 , binaryName = " pow"
267- , binarySymbol = Just " ^"
292+ , binarySymbol = Just " ^^"
293+ , binaryCommutative = False
294+ , binaryPrecedence = 8
295+ }
296+ )
297+
298+ (.^) ::
299+ ( Columnable (BaseType a )
300+ , Columnable (BaseType b )
301+ , Num (BaseType a )
302+ , Integral (BaseType b )
303+ , NumericWidenOp (BaseType a ) (BaseType b )
304+ , NullLift2Op a b (BaseType a ) a
305+ , Num (Promote (BaseType a ) (BaseType b ))
306+ ) =>
307+ Expr a -> Expr b -> Expr a
308+ (.^) =
309+ Binary
310+ ( MkBinaryOp
311+ { binaryFn = applyNull2 (^)
312+ , binaryName = " pow"
313+ , binarySymbol = Just " ^^"
268314 , binaryCommutative = False
269315 , binaryPrecedence = 8
270316 }
271317 )
272- expr
273- (Lit i)
0 commit comments