precog-bot on v0.18.6
djspiewak on v0.18.x
Set up new infrastructure Bumped to newer slamdata-predef Added repl to the aggregation and 2 more (compare)
djspiewak on infra
Apparently we need *both* versi… (compare)
djspiewak on infra
Added repl to the aggregation (compare)
djspiewak on infra
Bumped to newer slamdata-predef (compare)
djspiewak on infra
Set up new infrastructure (compare)
apo
…
Left
to say “don’t recurse”
Fix[F]
How do I approach the problem of designing an AST for an SQL-like language that would allow for using matryoshka?
The issue I'm having right now is that if I have eg something like this, simplified:
sealed trait Expr
case class Select(fields: List[String], distinct: Boolean) extends Expr
sealed trait From
case class TableName(get: String) extends From
case class Subquery(expr: TopLevelQuery) extends From
case class TopLevelQuery(select: Select, from: From) extends Expr
definitions of TopLevelQuery
and e.g From
are "mutually" recursive (same would happen for join
, union
, in
etc).
I can't come up with decomposition of this into non-self-referential set of ADT leaves. For example, how do I express TopLevelQuery
as a GADT?
Am I approaching this from the right side? What are my options here?
zipAlgebras
for parallel composition, multiple ways to do sequential composition (e.g., zygo
), then there are ways to combine algebras and coalgebras (e.g., hylo
). And other stuff as well.
AddF
case can easily be handled with an addToMult: ExprF[Fix[ExprF]] => ExprF[Fix[ExprF]]
function. Notice that that’s not strictly an algebra, but you can do addToMult >>> (_.embed)
or addToMult <<< (_.project)
to turn it into an Algebra or Coalgebra, respectively.
ExprF[Fix[ExprF]] => ExprF[Fix[ExprF]]
but... I still don't get it how can I compose it (or an Algebra after the composition with (_.embed)
) with e.g. evaluateInt
algebra to5.hylo(addToMulAlg >>> evaluateInt, unfoldSum)
), I'd like to do substitution and evaluation at once. Is that possible?
addToMulAlgApo[A: Eq]: ExprF[A] => ExprF[Either[Fix[ExprF], A]]
, which I maybe should have presented that way initially anyway, or addToMulAlgNT: ExprF[Int] => ExprF[Int]
. With the former, you can do case AddF(l,r) => if (l == r) MulF(Left(NumF(2).embed), Right(r)) else AddF(Right(l), Right(r))
and in the latter case a@AddF(l,r) => if (l == r) MulF(2, r) else a
. They mean slightly different things, which may not matter for you. The former will treat the 2
as atomic, and not process that branch any more, but the latter will continue processing the branch, so maybe it becomes AddF(NumF(1), NumF(1))
, depending on your unfoldSum
. And then you could (with the latter algebra) do 5.hylo(evaluateInt, addToMulAlgNT <<< unfoldSum)
. The former case is a little more complicated, because I don’t think there’s a common name for a hylo that combines cata and apo. But (with a bunch more type annotations, 5.ghylo(distCata, distApo, evaluateInt, addToMultAlgApo <<< unfoldSum)
should do the right thing.
addToMult
on the unfold side. It doesn’t make sense (I don’t think) to do it in the same pass on the fold side, because by the time you got to AddF(l, r)
, l
and r
would already be evaluated. So, no point in AddF(5,5)
→ MulF(2, 5)
→ 10
. But, you could do that with 5.hylo(evaluateInt <<< addToMulAlgNT, unfoldSum)
.
ExprF[Int] => ExprF[Int]
). My example can be silly at some point (which you inevitably have noticed) but all I wanted to know with it was how can I do some desugarnig/transformation on the fly. Thx once again for your help!
<<<
and >>>
in either Scalaz or Cats should be able to make something like alg <<< nat.apply
work. Algebra
and Coalgebra
are already Function1
, so they should be enriched with those Category
operators. Like nat.apply <<< coalg
might not work, since apply
is a method. But then (nat.apply[A](_)) <<< coalg
would work or coalg >>> nat.apply
.
Expr[+A]
the base case is Literal[A](value: Integer)
. I would like to have multiple types: NumberExpr, PointExpr, PolygonExpr as well as their sequenced equivalents. The operations would mix types, e:g: Voronoi(extent: PolygonExpr, seeds: Seq[PointExpr]) extends SeqExpr[Polygon]]
(perhaps?). How achievable is this?