Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Conversation

@cryogenian
Copy link
Member

Printer, search interpreter and JArray example

@garyb Could you please take a look?

@cryogenian cryogenian requested a review from garyb March 8, 2017 15:40
Copy link
Member

@garyb garyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of comments, I'll stop for now and then resume again once we've decided whether to do the EJson stuff, etc.


import Matryoshka (class Recursive, Algebra, cata, transParaT, project)

import Debug.Trace as DT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Debug.Trace 😄

, orderBy Maybe (OrderBy a)
}
| Select (SelectR a)
| Parens a
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we could use EJson rather than having constructors for all the literals in here? I don't think there are any EJson literals that don't have a corresponding SQL^2 representation. SQL^2 will need an additional set literal though.

If there's some problem with that I'm not thinking of, I have another related suggestion - although this is kinda a personal-preference thing - there might be some value in separating literals out into their own ADT, and just having a Literal (LiteralF a) constructor in SqlF. It simplified some stuff when I applied it in PS anyway.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, using EJson is a good idea. Technically you could use Coproduct SqlF EJsonF where SqlF is the part of SQL2 that is not EJson.

Remember in SQL2 you can do things like this:

SELECT {d.dynamic_field : [d.another_one]} FROM `/foo/` AS d

i.e. "literals" can recursively contain arbitrary SQL2 / EJSON.

ArrayLiteral lst →
ArrayLiteral $ map f lst
Parens t →
Parens $ f t
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this not a derivable functor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, there is Tuple a a

LeftJoin"left join"
RightJoin"right join"
FullJoin"full join"
InnerJoin"inner join"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a general comment, but here seems like a good a place as any... should we render the SQL-syntax-stuff as all uppercase perhaps? That seems more conventional to me; and I tend to write it that way when doing so by hand as it makes it easier to spot the parts that are identifiers, etc.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

import SqlSquare.Utils (type (×), (∘), (⋙))

_Newtype n t. Newtype n t Iso' n t
_Newtype = iso unwrap wrap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import SqlSquare.AST (SqlF(..), Relation, GroupBy(..), OrderBy, BinaryOperator, UnaryOperator, (∘), SelectR, Case(..), Projection(..))

vari t. Corecursive t SqlF String t
vari t. Corecursive t (SqlF EJsonF) String t
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can leave EJsonF polymorphic for a bunch of these...

@cryogenian
Copy link
Member Author

  • Removed Debug.Trace
  • AST has polymorphic Literal l, it's EJsonF here
  • Removed _Newtype
  • Capitalized keywords
  • Made smart constructors polymorphic

@cryogenian
Copy link
Member Author

Ah! Yep, added Foldable and Traversable instances. Actually Search example could be rewritten using cataM for checking fields/labels but it's really tedious :)

@cryogenian
Copy link
Member Author

  • Updated to ejson with proper date|time
  • Added constructors and lenses for date|time literal

@garyb is this good to go?

Copy link
Member

@garyb garyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's going to be great to be able to replace our string munging with this!

foldr f a (OrderBy xs) = F.foldr (flip (F.foldr f)) a xs
instance traversableOrderByT.Traversable OrderBy where
traverse f (OrderBy xs) = map OrderBy $ T.traverse (T.traverse f) xs
sequence = T.sequenceDefault
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think derive newtype instance should work for Foldable / Traversable here?


_Splice
t
. (Recursive t (S.SqlF EJ.EJsonF), Corecursive t (S.SqlF EJ.EJsonF))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a pretty minor thing, but we could make the lenses that aren't literal-specific polymorphic in SqlF l too perhaps. I wouldn't hold up this PR for that though!

@cryogenian
Copy link
Member Author

I've made lenses more polymorphic, but OrderBy foldable instance isn't derivable :(

@garyb
Copy link
Member

garyb commented Mar 10, 2017

Oh well! Just thought it was worth a try.

@cryogenian cryogenian merged commit 2d46fb9 into slamdata:master Mar 10, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants