Skip to content

Instantly share code, notes, and snippets.

View mads-hartmann's full-sized avatar

Mads Hartmann mads-hartmann

View GitHub Profile
@mads-hartmann
mads-hartmann / NList.scala
Created September 4, 2013 12:44
Attempt at implementing `++` for a statically sized list
object NList {
import Nat._
sealed trait NList[L <: Nat, A] {
def ++[B >: A, M <: Nat](other: NList[M, B])
(implicit sum: Plus[L, M]): NList[sum.Out, B]
}
case object NNil extends NList[Zero, Nothing] {
@mads-hartmann
mads-hartmann / Nat.scala
Created September 3, 2013 13:02
Trying to express a GADT in Scala
/*
Trying to express the following GADTs in Scala. It's taken from
http://eb.host.cs.st-andrews.ac.uk/drafts/tfp08.pdf (page 5)
data Z
data S n
data Nat :: * -> * where
Zero :: Nat Z
@mads-hartmann
mads-hartmann / semantic-search-talk
Last active December 16, 2015 09:18
My (rejected) proposal to Scala Days 2013. Maybe next year :)
As your code-base increases in size and you get more comfortable with
advanced Scala features you slowly reach a point where grep simply isn’t
sufficient to search through your projects; This has lead to the development
of Semantic Search, a plugin for Scala IDE for Eclipse that simplifies
code navigation, understanding, and refactoring.
In this talk Mads will show his work on Semantic Search with a live demo
of some of the features, including:
• Finding all occurrence of any Scala entity, even implicits.
@mads-hartmann
mads-hartmann / log
Created January 18, 2013 22:39
Failure log
Madss-MacBook-Pro:scala mads379$ ant all.clean
Buildfile: /Users/mads379/dev/projects/open-source/scala/build.xml
strap.clean:
[delete] Deleting directory /Users/mads379/dev/projects/open-source/scala/build/strap
pack.clean:
[delete] Deleting directory /Users/mads379/dev/projects/open-source/scala/build/pack
init.jars.check:
@mads-hartmann
mads-hartmann / scalacheck-output.txt
Created October 16, 2012 09:20
ScalaCheck Output That I don't understand
// The output.
info] ! Multiset.remove: Falsified after 1 passed tests.
[info] > ARG_0: (ListMultiset(, ),) <<<---- this is what looks weird, but I guess it's a ListMultiset with "" (no space)," " (a space) and the string is "" (no space)
[info] ! Multiset.remove: Falsified after 7 passed tests.
[info] > ARG_0: (ListMultiset(),)
// The specification
property("remove") = forAll(genMultisetWithString) { ((ms: Multiset[String], s: String) =>
@mads-hartmann
mads-hartmann / QueryExample.scala
Created September 26, 2012 12:14
Multiset Use-Case
package com.sidewayscoding.usecase
import com.sidewayscoding.immutable.ListMultiset
import com.sidewayscoding.Multiset
object QueryExample {
def main(args: Array[String]) {
sealed abstract class WithId(val id: String) {
override def equals(other: Any) = other match {
@mads-hartmann
mads-hartmann / ShoppingCart.scala
Created September 25, 2012 11:40
Shopping Cart use-case
object ShoppingCart {
/*
* Data has been taken from http://www.freebase.com/view/book/book_edition
*/
implicit val mergeableItem = new Mergeable[Book] {}
case class Book(name: String,
creditedTo: Option[String],
@mads-hartmann
mads-hartmann / custom-equiv-set.scala
Created September 12, 2012 12:27
Specifying a custom equivalence relation for sets
case class Person(name: String, age: Int)
val p1 = Person("Mads",22)
val p2 = Person("Mikkel",22)
implicit val eq: Equiv[Person] = new Equiv[Person] {
def equiv(x: Person, y: Person) = x.age == y.age
}
Set(p1,p2) // Set(Person(Mads,22), Person(Mikkel,22))
@mads-hartmann
mads-hartmann / sbt-ensime-debug-info.txt
Created August 26, 2012 19:34
SBT ENSIME debug info
Hi,
Here's some detailed info.
-- DIR info
$ pwd
/Users/mads379/dev/projects/open-source/ensime
$ ll
total 64
@mads-hartmann
mads-hartmann / toggle-maximize-buffer.el
Created August 20, 2012 10:05
An Emacs function to temporarily make one buffer fullscreen. You can quickly restore the old window setup.
(defun toggle-maximize-buffer () "Maximize buffer"
(interactive)
(if (= 1 (length (window-list)))
(jump-to-register '_)
(progn
(set-register '_ (list (current-window-configuration)))
(delete-other-windows))))
;; Bind it to a key.