• Stars
    star
    185
  • Rank 208,271 (Top 5 %)
  • Language
    Scala
  • License
    Apache License 2.0
  • Created almost 6 years ago
  • Updated almost 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

scala-typed-holes

This is a Scala compiler plugin to emulate the "typed holes" feature of Haskell, Idris, Agda, etc.

Whenever you use ??? in your code, the compiler plugin will generate a compiler warning containing useful information about it.

For example, given the Scala code

package example

object Example {

  def foo(x: Int, y: String): Boolean = {
    if (y.length == x) {
      ??? // TODO implement!
    } else {
      true
    }
  }

  def bar(x: Int): String = x match {
    case 0 => "zero"
    case 1 => "one"
    case _ => ???
  }

}

you'll get warnings that look something like this:

[warn] /Users/chris/code/scala-typed-holes/src/test/scala/example/Example.scala:7:7:
[warn] Found hole with type: Boolean
[warn] Relevant bindings include
[warn]   x: Int (bound at Example.scala:5:11)
[warn]   y: String (bound at Example.scala:5:19)
[warn]
[warn]       ??? // TODO implement!
[warn]       ^
[warn] /Users/chris/code/scala-typed-holes/src/test/scala/example/Example.scala:16:15:
[warn] Found hole with type: String
[warn] Relevant bindings include
[warn]   x: Int (bound at Example.scala:13:11)
[warn]
[warn]     case _ => ???
[warn]               ^

Named holes

The plugin also supports named holes. Instead of using ???, you can give custom names to your holes.

For example, code like this

def hello(args: Array[String]): Option[Result] = Foo.doStuff(args) match {
  case Left(error)  => __left
  case Right(x)     => __right
}

will result in warnings like this

Found hole 'left' with type: Option[Result]
Relevant bindings include
  args: Array[String] (bound at input.scala:11:13)
  error: String (bound at input.scala:12:15)

    case Left(error)  => __left
                         ^

Named holes must start with a double underscore.

Warning: if you happen to use a naming convention that includes double underscores (which is pretty rare in Scala), this plugin will probably trash your code!

How to use

In sbt:

addCompilerPlugin("com.github.cb372" % "scala-typed-holes" % "0.1.11" cross CrossVersion.full)

The plugin is published for the following Scala versions:

  • 2.11.12
  • 2.12.15
  • 2.13.{0, 1, 2, 3, 4, 5, 6, 7, 8}

Changing the log level

By passing a compiler option -P:typed-holes:log-level:<level>, you can control the severity with which holes are logged.

  • info means holes will be logged as informational messages
  • warn means holes will be logged as compiler warnings
  • error means holes will be logged as compiler errors, so your program will fail to compile if it contains any holes.

The default behaviour is to log holes as warnings.

If you are using sbt, you can pass the option like this:

scalacOptions += "-P:typed-holes:log-level:info"

More Repositories

1

scalacache

Simple caching in Scala
Scala
772
star
2

cats-retry

Scala
278
star
3

sbt-explicit-dependencies

Scala
255
star
4

line-count

A line counter for GitHub-hosted repositories, built with node.js
JavaScript
144
star
5

sbt-client

A thin client for sbt
Rust
93
star
6

free-vs-tagless-final

Scala
80
star
7

metrics-sigar

Metrics + Hyperic Sigar for OS-level monitoring
Java
77
star
8

automagic

Boilerplate-free model transformation in Scala
Scala
33
star
9

ReengLegacySoft

Code for the book Re-Engineering Legacy Software
Java
33
star
10

gke-vpc-peering-tutorial

HTML
32
star
11

web-app-functional-style

Scala
32
star
12

scalac-plugin-basic

Scala
28
star
13

cats-selective

Scala
27
star
14

reinforcement-learning-in-scala

Source code for Reinforcement Learning in Scala talk
Scala
26
star
15

scala-ascii-art

A simple Ascii art generator. A toy project to help me learn Scala. Pretty much a port to Scala of this: http://www.bestinclass.dk/index.php/2010/02/my-tribute-to-steve-ballmer/
Scala
23
star
16

scala-thank-you

Scala
18
star
17

type-class-derivation-in-scala-3

Scala
17
star
18

intellij-idris

Scala
15
star
19

sbt-classy

Scala
14
star
20

externalized

A handy DSL that makes it easier to work with external processes in Java
Java
13
star
21

cli-tools-skills-amnesty

Lesson notes for CLI tools training
Vim Script
12
star
22

scala-native-example-webserver

Scala
11
star
23

pakkas

An implementation of Basic Paxos, including leader election, in Akka.
Scala
11
star
24

jersey-jetty-guice-archetype

A Maven archetype for creating a standalone REST API-serving application
Java
11
star
25

scoogle

Hoogle for Scala (just a proof of concept, mostly smoke and mirrors)
Scala
10
star
26

observed-logstash

A plugin for Observed that runs an Elasticsearch query and checks the number of matching logs as a sign of healthiness
Ruby
10
star
27

scalamatsuri-my-first-macro

マクロ入門サンプル
Scala
9
star
28

docker-sample

Example Docker container for a Java webapp dependent on Tomcat + Nginx + Maven + Git
Shell
9
star
29

scala-school

Intermediate level (whatever that means) Scala training at the Guardian
Scala
8
star
30

fedis

A mock Redis server built with Finagle
Scala
7
star
31

two-to-tango

A simple app to help people find pair-programming buddies
Scala
7
star
32

play-forms-tutorial

Scala
6
star
33

dotfiles

Vim Script
6
star
34

jmh-plot

CLI tool to render JMH benchmark results using gnuplot
Scala
6
star
35

dispatch-example

Dispatchライブラリの使い方のちょっとしたサンプル
Scala
6
star
36

imperials

A data repository and dashboard for Yammer Metrics.
Scala
6
star
37

idris-for-scala-devs

Idris
5
star
38

phone-home

A Javascript client and Scalatra server for collecting client-side errors and diagnostics
JavaScript
5
star
39

elasticsearch-rspec-example

A simple Rails app showing how to use Rspec with Elasticsearch/Tire
Ruby
5
star
40

analysing-git-commit-graphs-with-droste

Scala
4
star
41

forks

A better UI for listing the forks of a Github project
Scala
4
star
42

obscure-cricket-stats

Bot that tweets randomly chosen cricket stats
HTML
4
star
43

staged-programming-in-scala-3

Scala
4
star
44

prisms

Scala
3
star
45

enumerate

Scala
3
star
46

aws-incremental-search

A Chrome extension to make the AWS console home screen easier to use
JavaScript
3
star
47

sbt-write-output-to-file

sbt plugin that writes the stdout of sbt run to a file
Scala
3
star
48

coc-github-users

TypeScript
3
star
49

cats-tagless-example

Scala
3
star
50

vector-foldRight-benchmark

Scala
3
star
51

massaging-case-classes-with-shapeless

Scala
2
star
52

useless-crap

Track your unnecessary spending
Scala
2
star
53

scala-beyond-the-basics

Scala
2
star
54

morocco

Rust
2
star
55

abstractiterator

Scala
2
star
56

meta-prog-shapeless-talk

Scala
2
star
57

rl-in-scala

HTML
2
star
58

Java7Sandbox

Messing around with the new features in JDK 7
Java
2
star
59

mfa-example

Haskell
2
star
60

sudoxir

A parallel brute-force Sudoku solver written in Elixir
Elixir
2
star
61

tweet-punchcard

Simple Heroku app to display Twitter activity as a punchcard
Python
2
star
62

Asakai

A sample Play application I made for a company presentation
Scala
2
star
63

coursera

Coursera programming answers
Scala
2
star
64

s3-encrypt

Scala
2
star
65

json-web-tokens

Scala
2
star
66

aws-prod-chrome-extension

JavaScript
2
star
67

finagle-beanstalk

A Scala client for beanstalkd, based on Finagle RPC framework.
Scala
2
star
68

copy_info_from_parent_issue

A Redmine plugin that makes it easier to create child tickets
Ruby
2
star
69

my-php-app

Shell
1
star
70

memoize-dotty

Scala
1
star
71

persevere

A library for asynchronous retries
Java
1
star
72

WinnersLosers

A simple Python script to parse historical shares info from a file and create a portfolio of winners and losers.
Python
1
star
73

wreq4s

Scala
1
star
74

theres-wally

Jupyter Notebook
1
star
75

spotifyify

A command-line tool for importing your local music collection into Spotify
Haskell
1
star
76

ordasity-example

A simple example of Boundary's Ordasity library. An Ordasity cluster for searching Twitter.
Scala
1
star
77

programming-trick-shots

Assembly
1
star
78

mu-tracing-example

Scala
1
star
79

van-emde-boas

Scala
1
star
80

play-configurable-ningwsplugin

Scala
1
star
81

kafka-notifications

A proof-of-concept for using Kafka for real-time notifications
Scala
1
star
82

50apps

My entries for the 50 Apps in 50 Weeks Challenge
Python
1
star
83

PageWatcher

A simple Play app to watch for changes in a given set of webpages
Scala
1
star
84

unbounded-spigot-fs2

Scala/fs2 implementation of Unbounded Spigot Algorithms for the Digits of Pi
Scala
1
star
85

dining-philosophers-pony

An implementation of the Dining Philosophers problem in Pony
Pony
1
star
86

ScalaSnippets

Random code snippets and utilities
Scala
1
star
87

raft

An implementation of the Raft consensus algorithm in Scala
Scala
1
star
88

cb372.github.com

Scala
1
star
89

mu-haskell-sandbox

Haskell
1
star
90

KagemaiCommenter

An SVN post-commit script for posting comments to Kagemai
Ruby
1
star
91

scalafix-example

Scala
1
star
92

elasticsearch-test-example

A simple example showing how to use tlrx/elasticsearch-test
Java
1
star
93

rpscala

rpscala
Scala
1
star