Skip to content

Instantly share code, notes, and snippets.

@zeptometer
zeptometer / gsoc-final-report.md
Last active August 28, 2023 11:18
GSoC Final Report: Enhancement of quote pattern matching in Scala 3

GSoC Final Report: Enhancement of quote pattern matching in Scala 3

Summary

In this project, I worked on expanding the capability of HOAS patterns of quote pattern matching feature under the mentorship by Nicolas Stucki. In addition to several bugfix PRs, I made a PR that allows HOAS patterns to hold type arguments. This feature will enable quote patterns to analyze the structure of polymorphic functions/methods, which is not feasible in the current quote pattern matching.

Introduction

Scala 3 macros support quote patterns that allow programmers to compare a quoted code fragment to another or to analyze its structure. When one analyzes the structure of a code fragment, one must be aware of binding structures: which variables occur freely in the code fragment and which don't. Higher-order abstract syntax (HOAS) patterns manages such informa

@zeptometer
zeptometer / macro_1.scala
Created June 3, 2023 14:48
Issue-17105 test case
// Macro_1.scala
import scala.quoted.*
inline def testExpr(inline body: Any) = ${ testExprImpl('body) }
def testExprImpl(body: Expr[Any])(using Quotes): Expr[String] =
body match
case '{ def g(y: Int) = "hello" * y; $a(g): String } =>
'{ $a((z:Int) => "this is " + z.toString()) }
case _ => Expr("not matched")
def app = hoge((y) => y + 1) // expected true, but got false
.voice-state {
height: unset !important;
margin-bottom: 16px !important;
display: flex;
}
.avatar {
height: 100px !important;
width: 100px !important;
opacity: 50%;
fun toMap(flags: Int): Array<BooleanArray> {
return Array(4) { x ->
BooleanArray(4) { y ->
(flags shr (x * 4 + y)) and 1 == 1
}
}
}
fun isValidMoat(moat: Array<BooleanArray>): Boolean {
fun getInitPos(moat: Array<BooleanArray>): Pair<Int, Int> {
@zeptometer
zeptometer / fuga.satyg
Last active January 18, 2021 05:40
Minimal code to reproduce satysfi issue
module Fuga : sig
val a : string
end = struct
let a = `fuga`
end
# Packages matching: installed
# Name # Installed # Synopsis
angstrom 0.15.0 Parser combinators built for speed and memory-efficiency
asn1-combinators 0.2.4 Embed typed ASN.1 grammars in OCaml
astring 0.8.5 Alternative String module for OCaml
atd 2.2.1 Parser for the ATD data format description language
atdgen 2.2.1 Generates efficient JSON serializers, deserializers and validators
atdgen-runtime 2.2.1 Runtime library for code generated by atdgen
base v0.14.0 Full standard library replacement for OCaml
base-bigarray base
@zeptometer
zeptometer / nbe.bel
Created March 31, 2019 14:42
Normalization by Evaluation written in Beluga
LF tp : type =
| base : tp
| arr : tp → tp → tp
;
LF term : tp → type =
| app : term (arr a b) → term a → term b
| lam : (term a → term b) → term (arr a b)
;
all:
satysfi -b main.saty -o ../main.pdf
@zeptometer
zeptometer / hello.scm
Last active February 13, 2018 16:10
syntax-rules backend for ELVMの途中報告
;;; CK machine
;;; For detail, see http://okmij.org/ftp/Scheme/macros.html#ck-macros
(define-syntax ck
(syntax-rules (quote)
((_ () 'v) 'v)
((_ (((op ...) ea ...) . s) 'v)
(ck s "arg" (op ... 'v) ea ...))
((_ s "arg" (op va ...))
(op s va ...))
((_ s "arg" (op ...) 'v ea1 ...)