Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore removing nested tuples and eithers #75

Open
sergei-shabanau opened this issue Mar 4, 2020 · 0 comments
Open

Explore removing nested tuples and eithers #75

sergei-shabanau opened this issue Mar 4, 2020 · 0 comments
Assignees

Comments

@sergei-shabanau
Copy link
Member

Given we have the following combinators

def ~ [SI1 <: SI, SO1 >: SO, E1 >: E, B](that: Grammar[SI1, SO1, E1, B]): Grammar[SI1, SO1, E1, A /\ B]
def | [SI1 <: SI, SO1 >: SO, E1 >: E, B](that: Grammar[SI1, SO1, E1, B]): Grammar[SI1, SO1, E1, A \/ B]

that produce nested structures when chained, e.g.

val g1: Grammar[SI1, SO1, E, ((A, B), C)] = a ~ b ~ c

Explore the concept of building a parser/printer that skips creation of nested structures when executed.

Idea is to use a witness type with 2 parameters

type G[_, _]

where 1st is a phantom type to capture what is produced by using parser combinators and 2nd is some representation of the 1st.

For example

sealed trait Equiv[A, Repr]
object Equiv {
  def caseClass1[Z, A](f: A => Z, g: Z => Option[A]): Equiv[A, Z] = ???
  def caseClass2[Z, A, B](f: (A, B) => Z, g: Z => Option[(A, B)]): Equiv[(A, B), Z] = ???
  def caseClass3[Z, A, B, C](f: (A, B, C) => Z, g: Z => Option[(A, B, C)]): Equiv[((A, B), C), Z] = ???
}

This way a

final case class Person(name: String, age: Int, address: String)

can be isomorphic to

((String, Int), String)

via means of Equiv.

def to[Z](implicit equiv: Equiv[A, Z]): Grammar[SI, SO, E, Z]

can be used to describe an intent for isomorphic transformation.
Existing program in terms of grammars should be kept to be further optimized into an efficient code that is not doing extra allocations.

@sergei-shabanau sergei-shabanau self-assigned this Mar 25, 2020
sergei-shabanau added a commit that referenced this issue Mar 25, 2020
sergei-shabanau added a commit that referenced this issue Mar 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant