Skip to content

Instantly share code, notes, and snippets.

View larsrh's full-sized avatar
🏝️
On hiatus.

Lars Hupel larsrh

🏝️
On hiatus.
View GitHub Profile
@larsrh
larsrh / tut-cli.sh
Created October 1, 2016 07:48
Running tut on the command line with coursier
# Uses Alex Archambault's coursier launcher
# Download as follows:
# $ curl -L -o coursier https://git.io/vgvpD && chmod +x coursier
# ... or refer to instructions here: <https://github.com/alexarchambault/coursier>
# list any dependencies here
COURSIER_CLASSPATH="$(coursier fetch -p com.chuusai:shapeless_2.11:2.3.1)"
# this downloads and launches tut in a seperate step
# the 'classpath' argument is being interpreted by scalac
@larsrh
larsrh / TestSpec.scala
Created September 9, 2016 08:32
Exceptions in AfterAll
package test
import org.specs2.Specification
import org.specs2.specification.AfterAll
class TestSpec extends Specification
with AfterAll { def is = s2"""
Test spec
@larsrh
larsrh / Scratch.thy
Created August 3, 2016 20:35
Proving a lemma about rev using parametricity
theory Scratch
imports Main
begin
interpretation lifting_syntax .
definition "graph f = (λx y. y = f x)"
lemma graph_map: "list_all2 (graph f) = graph (map f)"
proof (rule ext)+
@larsrh
larsrh / optics.scala
Last active July 24, 2016 16:16 — forked from julien-truffaut/optics.scala
Attempt to get single compose method between optics
package vanilla
sealed trait Optic[G[_,_] <: Optic[G, _, _], S, A] {
def compose[F[_, _] <: Optic[F, _, _], B](o: F[A, B])(implicit lub : Lub[G,F]) : lub.T[S, B] =
lub.compose(self, o)
def self: G[S,A]
def desc: List[String]
}
case class Traversal[A,B](desc : List[String]) extends Optic[Traversal,A,B] {
@larsrh
larsrh / postbuild.groovy
Created July 17, 2016 09:33
Jenkins "Groovy Postbuild" script to deploy artifacts
def ws = manager.build.project.workspace
def web = ws.child("web")
def target = new hudson.FilePath(new java.io.File("/var/www/afp-devel"))
target.mkdirs()
target.deleteContents()
web.copyRecursiveTo(target)
@larsrh
larsrh / list.scala
Last active July 22, 2016 07:50
safe head/tail on lists using covariance
// Initial idea courtesy of @dwijnand
// Improved by @fthomas
sealed trait List[+T] {
def head: Option[T]
}
final case class Cons[T](h: T, t: List[T]) extends List[T] {
val head: Some[T] = Some(h)
}
@larsrh
larsrh / nats.scala
Last active January 21, 2016 15:16
Example for the paper "System Description: Translating Scala Programs to Isabelle/HOL"
import leon.annotation._
import leon.collection._
import leon.lang._
@isabelle.typ(name = "Nat.nat")
sealed abstract class Nat {
@isabelle.function(term = "op <=")
def <=(that: Nat): Boolean = this match {
case Zero() => true
@larsrh
larsrh / resolve.scala
Created November 22, 2015 09:59
Resolving multiple artifacts
def fetchPIDE(version: Version)(implicit ec: ExecutionContext): Future[List[Path]] = {
val repositories = Seq(Repository.ivy2Local, Repository.mavenCentral, Repository.sonatypeReleases)
val files = coursier.Files(
Seq("https://" -> new File(sys.props("user.home") + "/.libisabelle/cache")),
() => sys.error("impossible")
)
val cachePolicy = Repository.CachePolicy.Default
@larsrh
larsrh / collections.hs
Last active October 9, 2015 14:39
Haskell collection redesign
-- Joke implementation of a joke idea
-- Scala-2.8-style collections in Haskell
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE DefaultSignatures #-}
@larsrh
larsrh / Scratch.thy
Created September 24, 2015 08:21
Scala World 2015
theory Scratch
imports Main
begin
fun insert :: "'a::linorder ⇒ 'a list ⇒ 'a list" where
"insert x [] = [x]" |
"insert x (y # ys) = (if x ≤ y then x # y # ys else y # insert x ys)"
inductive sorted :: "'a::linorder list ⇒ bool" where
empty: "sorted []" |