on dev help sign in
renaming and type application
commitb00ae4cb9ed0e28f4b747be3e4d6100e958d57bd authorEitan Chatav <eitan@EEM109LMBP-1.local> dateTue 3 Sep 2019, 21:32 (7 years ago) parent66d88ed
6 files changed+59−53
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+21−21 squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+28−22 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Comparison.hs+6−6 squeal-postgresql/src/Squeal/PostgreSQL/Expression/Logic.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/Expression/TextSearch.hs+1−1 squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+2−2
squeal-postgresql/src/Squeal/PostgreSQL/Definition.hs+21−21
@@ -54,8 +54,8 @@ module Squeal.PostgreSQL.Definition
5454 , createSetFunction
5555 , createOrReplaceSetFunction
5656 , createBinaryOp
57− , createUnaryOpL
58− , createUnaryOpR
57+ , createLeftOp
58+ , createRightOp
5959 , TableConstraintExpression (..)
6060 , check
6161 , unique
@@ -1220,17 +1220,17 @@ createOrReplaceSetFunction fun args rets fundef = UnsafeDefinition $
12201220 renderRet (ty `As` col) = renderSQL col <+> renderSQL ty
12211221
12221222createBinaryOp
1223− :: ( Has sch schemas schema
1223+ :: forall op fun sch schemas schema x y z.
1224+ ( Has sch schemas schema
12241225 , Has fun schema ('Function '[x,y] ('Returns z))
12251226 , KnownSymbol op )
1226− => Alias op
1227− -> Alias fun
1227+ => Alias fun
12281228 -> TypeExpression schemas x
12291229 -> TypeExpression schemas y
12301230 -> Definition schemas
12311231 (Alter sch (Create op ('Operator ('BinaryOp x y z)) schema) schemas)
1232−createBinaryOp op fun x y = UnsafeDefinition $
1233− "CREATE" <+> "OPERATOR" <+> renderSQL op
1232+createBinaryOp fun x y = UnsafeDefinition $
1233+ "CREATE" <+> "OPERATOR" <+> renderSymbol @op
12341234 <+> parenthesized (commaSeparated opdef)
12351235 where
12361236 opdef =
@@ -1238,34 +1238,34 @@ createBinaryOp op fun x y = UnsafeDefinition $
12381238 , "LEFTARG" <+> "=" <+> renderSQL x
12391239 , "RIGHTARG" <+> "=" <+> renderSQL y ]
12401240
1241−createUnaryOpL
1242− :: ( Has sch schemas schema
1241+createLeftOp
1242+ :: forall op fun sch schemas schema x y.
1243+ ( Has sch schemas schema
12431244 , Has fun schema ('Function '[x] ('Returns y))
12441245 , KnownSymbol op )
1245− => Alias op
1246− -> Alias fun
1246+ => Alias fun
12471247 -> TypeExpression schemas x
12481248 -> Definition schemas
1249− (Alter sch (Create op ('Operator ('UnaryOpL x y)) schema) schemas)
1250−createUnaryOpL op fun x = UnsafeDefinition $
1251− "CREATE" <+> "OPERATOR" <+> renderSQL op
1249+ (Alter sch (Create op ('Operator ('LeftOp x y)) schema) schemas)
1250+createLeftOp fun x = UnsafeDefinition $
1251+ "CREATE" <+> "OPERATOR" <+> renderSymbol @op
12521252 <+> parenthesized (commaSeparated opdef)
12531253 where
12541254 opdef =
12551255 [ "FUNCTION" <+> "=" <+> renderSQL fun
12561256 , "RIGHTARG" <+> "=" <+> renderSQL x ]
12571257
1258−createUnaryOpR
1259− :: ( Has sch schemas schema
1258+createRightOp
1259+ :: forall op fun sch schemas schema x y.
1260+ ( Has sch schemas schema
12601261 , Has fun schema ('Function '[x] ('Returns y))
12611262 , KnownSymbol op )
1262− => Alias op
1263− -> Alias fun
1263+ => Alias fun
12641264 -> TypeExpression schemas x
12651265 -> Definition schemas
1266− (Alter sch (Create op ('Operator ('UnaryOpR x y)) schema) schemas)
1267−createUnaryOpR op fun x = UnsafeDefinition $
1268− "CREATE" <+> "OPERATOR" <+> renderSQL op
1266+ (Alter sch (Create op ('Operator ('RightOp x y)) schema) schemas)
1267+createRightOp fun x = UnsafeDefinition $
1268+ "CREATE" <+> "OPERATOR" <+> renderSymbol @op
12691269 <+> parenthesized (commaSeparated opdef)
12701270 where
12711271 opdef =
squeal-postgresql/src/Squeal/PostgreSQL/Expression.hs+28−22
@@ -38,10 +38,10 @@ module Squeal.PostgreSQL.Expression
3838 , FunctionDB
3939 , unsafeFunction
4040 , function
41− , unsafeUnaryOpL
42− , unaryOpL
43− , unsafeUnaryOpR
44− , unaryOpR
41+ , unsafeLeftOp
42+ , leftOp
43+ , unsafeRightOp
44+ , rightOp
4545 , Operator
4646 , OperatorDB
4747 , unsafeBinaryOp
@@ -319,29 +319,35 @@ unsafeBinaryOp op x y = UnsafeExpression $ parenthesized $
319319 renderSQL x <+> op <+> renderSQL y
320320
321321binaryOp
322− :: (Has sch schemas schema, Has op schema ('Operator ('BinaryOp x1 x2 y)))
323− => Alias op -> OperatorDB schemas x1 x2 y
324−binaryOp = unsafeBinaryOp . renderSQL
322+ :: forall op sch schemas schema x y z.
323+ ( Has sch schemas schema
324+ , Has op schema ('Operator ('BinaryOp x y z)) )
325+ => OperatorDB schemas x y z
326+binaryOp = unsafeBinaryOp $ renderSymbol @op
325327
326−-- | >>> printSQL $ unsafeUnaryOpL "NOT" true
328+-- | >>> printSQL $ unsafeLeftOp "NOT" true
327329-- (NOT TRUE)
328−unsafeUnaryOpL :: ByteString -> x :--> y
329−unsafeUnaryOpL op x = UnsafeExpression $ parenthesized $ op <+> renderSQL x
330+unsafeLeftOp :: ByteString -> x :--> y
331+unsafeLeftOp op x = UnsafeExpression $ parenthesized $ op <+> renderSQL x
330332
331−unaryOpL
332− :: (Has sch schemas schema, Has op schema ('Operator ('UnaryOpL x y)))
333− => Alias op -> FunctionDB schemas x y
334−unaryOpL = unsafeUnaryOpL . renderSQL
333+leftOp
334+ :: forall op sch schemas schema x y.
335+ ( Has sch schemas schema
336+ , Has op schema ('Operator ('LeftOp x y)) )
337+ => FunctionDB schemas x y
338+leftOp = unsafeLeftOp $ renderSymbol @op
335339
336−-- | >>> printSQL $ true & unsafeUnaryOpR "IS NOT TRUE"
340+-- | >>> printSQL $ true & unsafeRightOp "IS NOT TRUE"
337341-- (TRUE IS NOT TRUE)
338−unsafeUnaryOpR :: ByteString -> x :--> y
339−unsafeUnaryOpR op x = UnsafeExpression $ parenthesized $ renderSQL x <+> op
340−
341−unaryOpR
342− :: (Has sch schemas schema, Has op schema ('Operator ('UnaryOpR x y)))
343− => Alias op -> FunctionDB schemas x y
344−unaryOpR = unsafeUnaryOpR . renderSQL
342+unsafeRightOp :: ByteString -> x :--> y
343+unsafeRightOp op x = UnsafeExpression $ parenthesized $ renderSQL x <+> op
344+
345+rightOp
346+ :: forall op sch schemas schema x y.
347+ ( Has sch schemas schema
348+ , Has op schema ('Operator ('RightOp x y)) )
349+ => FunctionDB schemas x y
350+rightOp = unsafeRightOp $ renderSymbol @op
345351
346352-- | >>> printSQL $ unsafeFunction "f" true
347353-- f(TRUE)
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Comparison.hs+6−6
@@ -163,7 +163,7 @@ isNotDistinctFrom = unsafeBinaryOp "IS NOT DISTINCT FROM"
163163(TRUE IS TRUE)
164164-}
165165isTrue :: null0 'PGbool :--> null1 'PGbool
166−isTrue = unsafeUnaryOpR "IS TRUE"
166+isTrue = unsafeRightOp "IS TRUE"
167167
168168{- | is false or unknown
169169
@@ -171,7 +171,7 @@ isTrue = unsafeUnaryOpR "IS TRUE"
171171(TRUE IS NOT TRUE)
172172-}
173173isNotTrue :: null0 'PGbool :--> null1 'PGbool
174−isNotTrue = unsafeUnaryOpR "IS NOT TRUE"
174+isNotTrue = unsafeRightOp "IS NOT TRUE"
175175
176176{- | is false
177177
@@ -179,7 +179,7 @@ isNotTrue = unsafeUnaryOpR "IS NOT TRUE"
179179(TRUE IS FALSE)
180180-}
181181isFalse :: null0 'PGbool :--> null1 'PGbool
182−isFalse = unsafeUnaryOpR "IS FALSE"
182+isFalse = unsafeRightOp "IS FALSE"
183183
184184{- | is true or unknown
185185
@@ -187,7 +187,7 @@ isFalse = unsafeUnaryOpR "IS FALSE"
187187(TRUE IS NOT FALSE)
188188-}
189189isNotFalse :: null0 'PGbool :--> null1 'PGbool
190−isNotFalse = unsafeUnaryOpR "IS NOT FALSE"
190+isNotFalse = unsafeRightOp "IS NOT FALSE"
191191
192192{- | is unknown
193193
@@ -195,7 +195,7 @@ isNotFalse = unsafeUnaryOpR "IS NOT FALSE"
195195(TRUE IS UNKNOWN)
196196-}
197197isUnknown :: null0 'PGbool :--> null1 'PGbool
198−isUnknown = unsafeUnaryOpR "IS UNKNOWN"
198+isUnknown = unsafeRightOp "IS UNKNOWN"
199199
200200{- | is true or false
201201
@@ -203,4 +203,4 @@ isUnknown = unsafeUnaryOpR "IS UNKNOWN"
203203(TRUE IS NOT UNKNOWN)
204204-}
205205isNotUnknown :: null0 'PGbool :--> null1 'PGbool
206−isNotUnknown = unsafeUnaryOpR "IS NOT UNKNOWN"
206+isNotUnknown = unsafeRightOp "IS NOT UNKNOWN"
squeal-postgresql/src/Squeal/PostgreSQL/Expression/Logic.hs+1−1
@@ -48,7 +48,7 @@ false = UnsafeExpression "FALSE"
4848-- | >>> printSQL $ not_ true
4949-- (NOT TRUE)
5050not_ :: null 'PGbool :--> null 'PGbool
51−not_ = unsafeUnaryOpL "NOT"
51+not_ = unsafeLeftOp "NOT"
5252
5353-- | >>> printSQL $ true .&& false
5454-- (TRUE AND FALSE)
squeal-postgresql/src/Squeal/PostgreSQL/Expression/TextSearch.hs+1−1
@@ -56,7 +56,7 @@ import Squeal.PostgreSQL.Schema
5656
5757-- | negate a `Squeal.PostgreSQL.Expression.Type.tsquery`
5858(.!) :: null 'PGtsquery :--> null 'PGtsquery
59−(.!) = unsafeUnaryOpL "!!"
59+(.!) = unsafeLeftOp "!!"
6060
6161-- | `Squeal.PostgreSQL.Expression.Type.tsquery` followed by
6262-- `Squeal.PostgreSQL.Expression.Type.tsquery`
squeal-postgresql/src/Squeal/PostgreSQL/Schema.hs+2−2
@@ -379,8 +379,8 @@ data ReturnsType
379379
380380data OperatorType
381381 = BinaryOp NullityType NullityType NullityType
382− | UnaryOpL NullityType NullityType
383− | UnaryOpR NullityType NullityType
382+ | LeftOp NullityType NullityType
383+ | RightOp NullityType NullityType
384384
385385{- | The schema of a database consists of a list of aliased,
386386user-defined `SchemumType`s.