Skip to content

Instantly share code, notes, and snippets.

View mads-hartmann's full-sized avatar

Mads Hartmann mads-hartmann

View GitHub Profile
__________________________________________________
Project definition:
__________________________________________________
version := "0.7"
resolvers += "Scala Tools Releases" at "http://scala-tools.org/repo-releases/"
libraryDependencies += "org.scalatest" % "scalatest" % "1.3" % "test"
@mads-hartmann
mads-hartmann / coding music
Created July 29, 2011 16:38
When I asked for music suitable as background music while coding, this is the answers I got
@heiflo: Deep Mix Moscow Radio www.deepmix.eu
@behaghel: JJ Cale
@franztaptanium: Steps from Hell
@peyloW: Deine Lakaien, Raubtier, Timoteij, VNV Nation, Dragon Force
@TwistedChaz: Portico Quartet - Knee-Deep in the North Sea (Album)
@ArmyOfBruce: Orbital
@tylerweir: di.fm
@mads-hartmann
mads-hartmann / scala.scala
Created August 8, 2011 19:29
just a scala file to show a syntax bug in chocolatapp
package org.lifty.engine
import java.io.File
import org.lifty.engine._
import scalaz._
import Scalaz._
/* This class is just used for debugging purposes */
object Main {
@mads-hartmann
mads-hartmann / syntax.selfml
Created August 8, 2011 19:34
Scala syntax for Chocolatapp (generated)
(root source.scala
(include @storage-modifiers)
(include @keywords)
(include @declarations)
(include @inheritance)
(include @imports)
(include @comments)
(include @block-comments)
(include @strings)
(include @initialization)
@mads-hartmann
mads-hartmann / ast_transformation.scala
Created August 11, 2011 13:00
Attempt to do AST Transformation
#!/bin/sh
exec scala "$0" "$@"
!#
/*
Subset of our Simple Java AST
*/
sealed abstract class SJStatement
case class SJAssert (assertion : SJExpression) extends SJStatement
@mads-hartmann
mads-hartmann / higher-rank polymorphic function with type bounds.scala
Created August 11, 2011 14:26
Attempt to create a higher-rank polymorphic function with type bounds
/*
I want to use a higher-rank polymorphic function when transforming an AST to generalize the
'traversal' so it can be separated from the actual transformation of each node.
This snippet of code doesn't quite capture my use case but it provokes the same compile error
as I get here: https://gist.github.com/1139579
*/
trait ~>[F[_],G[_], -UpperBound] {
def apply[A <: UpperBound](a: F[A]): G[A]
@mads-hartmann
mads-hartmann / sbt_error.txt
Created September 1, 2011 00:17
sbt error
Sooo, what is happening here?
[error] error while loading Diff, class file needed by Diff is missing.
[error] reference type Serializable of package scala refers to nonexisting symbol.
[error] class file needed by Diff is missing.
[error] reference type Serializable of package scala refers to nonexisting symbol.
[error] two errors found
[debug] Compilation failed (CompilerInterface)
Compilation failed
at xsbt.CompilerInterface.run(CompilerInterface.scala:93)
@mads-hartmann
mads-hartmann / demystify_state_monad.hs
Created September 21, 2011 21:26
This is an attempt to de-mystify how Control.Monad.State.get seems to magically create a State out of nothing.
{-
Dear reader,
This is an attempt to de-mystify how Control.Monad.State.get seems to
magically create a State out of nothing.
Here's an example taken from the documentation:
tick :: State Int Int
tick = do
@mads-hartmann
mads-hartmann / scala.scala
Created September 23, 2011 08:17
More statements in the for-comprehension wanted
val op1 = Some("test")
val op2 = Some("test")
val l1 = List(1,2,3)
val l2 = List(1,2,3)
val product: Option[List[(Int,Int)]] = for {
t1 <- op1
t2 <- op2
} yield l1.flatMap { l => l2.map { l2 => (l,l2) }}
@mads-hartmann
mads-hartmann / SCC-scalaz.scala
Created October 13, 2011 12:27
Strongly Connected Components algorithm implemented in Scala using ScalaZ
/*
This is implemented following the instructions in "The Design and Analysis of
Computer Algorithms, AHO Hopcroft Ullman, 1974".
The implementation uses a DFS to find the strongly connected components (SCCs)
of a graph. During the DFS the vertices are placed on a stack in the order
they are visited. Whenever a root is found, all vertices of the corresponding
SSC are on the top of the stack and are popped.