ken
is a Haskell-like DSL in Scala:
import com.github.okomok.ken._
// From: http://www.haskell.org/haskellwiki/State_Monad
object StateGame extends Main {
type GameValue = Int
type GameState = (Bool, Int)
// Pull the Monad explicitly.
val _M = MonadState[State.apply[GameState]]
import _M._
val playGame: String => _M.apply[GameValue] = {
case Nil => {
for {
(_, score) <- get
} yield score
}
case x :: xs => {
for {
(on, score) <- get
_ <- x match {
case 'a' if on => put(on, score + 1)
case 'b' if on => put(on, score - 1)
case 'c' => put(Bool.not(on), score)
case _ => put(on, score)
}
} playGame(xs)
}
}
val startState = (False, 0)
val main_ = IO.print { State.eval(playGame("abcaaacbbcabbab"))(startState) }
}
In ken, type-class instances are explicitly retrieved.
- Foolishly honest port of Haskell standard libraries.
- Variance-aware.
- Pulling type-class instances explicitly so that wildcard imports are removed.
- Type-level functions for partially-applied types.
- repository:
http://okomok.github.com/maven-repo/releases
- group id:
com.github.okomok
- artifact id:
ken_2.9.1
- version:
0.1.0
In Scala 2.9.x, add -Ydependent-method-types
to compiler options.
- ekmett/functorial - GitHub
- Parsec
- runarorama/scarpia - GitHub
- scalaz
- Browse Source
- Browse Test Source
- The Scala Programming Language
Shunsuke Sogame <okomok@gmail.com>