WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Match quoted tuple prepend #13956

@Adam-Vandervorst

Description

@Adam-Vandervorst

Compiler version

3.1.2-RC1-bin-20211025-968dd1b-NIGHTLY

Minimized code

import scala.quoted.*

def printallImpl[T <: NonEmptyTuple](xs: Expr[T])(using Quotes): Expr[Unit] =
  xs match
    case '{ $head *: (${tail}: Tuple) } =>
      '{ print($head); print(" *: "); println($tail) }
    case '{ ($fst, $snd) } =>
      '{ print($fst); print(", "); println($snd) }

inline def printall[T <: NonEmptyTuple](inline xs: T) = ${ printallImpl('{xs}) }
@main def example = printall((1, 2))

Output

1, 2

Expectation

1 *: Tuple(2)

I expect '{ $head *: (${tail}: Tuple) } to catch something matching '{ ($fst, $snd) }, but I'm new to this area.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions