you know mruby is the lightweight implementation of the Ruby language. it also works with php. I made this extension in my lunch time :)
git clone https://github.com/chobie/php-mruby.git --recursive
cd php-mruby
cd mruby
make
scala> type AndThen[F[_], G[_]] = { | |
| type Apply[A] = G[F[A]] | |
| } | |
defined type alias AndThen | |
scala> val x: (List AndThen Set)#Apply[Int] = null | |
x: scala.collection.immutable.Set[List[Int]] = null |
object KindPoly { | |
class Eq[A, B] | |
object Eq { | |
implicit def witness[A] = new Eq[A, A] | |
} | |
implicitly[Eq[{ type K = Int}, { type K = Int }]] | |
implicitly[Eq[{ type K = Int}, { type K = String }]] // Does not compile |
case class ReaderWriterStateT[R, W, S, F[_], A]( | |
run: (R, S) => F[(W, A, S)] | |
) { | |
def map[B](f: A => B)(implicit F: Functor[F]) | |
: ReaderWriterStateT[R, W, S, F, B] = | |
ReaderWriterStateT { | |
case (r, s) => F.map(run(r, s)) { | |
case (w, a, s) => (w, f(a), s) | |
} | |
} |
def index(id:String) = Action { | |
getFirstData(id) | |
} | |
private def getFirstData(id:String) = { | |
Cache.get(id) match { | |
case Some(id2) => getSecondData(id2) | |
case None => NotFound | |
} | |
} | |
private def getSecondData(id2:String) = { |
scala> import scala.language.experimental.macros | |
import scala.language.experimental.macros | |
scala> def unimplicitlyImpl[A: c.TypeTag](c: reflect.makro.Context) = { | |
| val A = implicitly[c.TypeTag[A]].tpe | |
| val i = c.inferImplicitValue(A, silent = true) | |
| if (i == c.mirror.EmptyTree) c.reify(()) | |
| else sys.error("unexpected implicit of type %s: %s".format(A, i)) | |
| } | |
unimplicitlyImpl: [A](c: scala.reflect.makro.Context)(implicit evidence$1: c.TypeTag[A])c.mirror.Expr[Unit] |
def NotVar(expr: Any): Any = macro NotVarImpl | |
def NotVarImpl(c: Context)(expr: c.Expr[Any]): c.Expr[Any] = { | |
import c.mirror._ | |
import reflect.api.Modifier.mutable | |
Expr((new Transformer{ | |
override def transform(tree:Tree):Tree = tree match{ | |
case ValDef(m,_,_,_) if m.hasModifier(mutable) => sys.error("can't use var !!!") | |
case _ => super.transform(tree) |
scala> val intp = new scala.tools.nsc.interpreter.IMain | |
intp: scala.tools.nsc.interpreter.IMain = scala.tools.nsc.interpreter.IMain@6875577e | |
scala> val holder = new scala.runtime.ObjectRef[Any] | |
holder: scala.runtime.ObjectRef[Any] = () | |
scala> intp.bind("holder", "scala.runtime.ObjectRef[Any]", holder) | |
holder: scala.runtime.ObjectRef[Any] = () | |
res16: scala.tools.nsc.interpreter.IR.Result = Success |
// original, broken version | |
def many[A](a: F[A]): F[List[A]] = { | |
lazy val y: Free.Trampoline[F[List[A]]] = z map (plus(_, point(Nil))) | |
lazy val z: Free.Trampoline[F[List[A]]] = y map (map2(a, _)(_ :: _)) | |
y.run | |
} | |
// trying to make sense of trampoline |
import scala.xml._ | |
object XMLStringLiteral extends App { | |
implicit class RichStringContext(self: StringContext) { | |
def xml(params: Any*): Elem = { | |
val Seq(first, rest@_*) = self.parts | |
val source = first + (params, rest).zipped.map{_+_}.mkString | |
XML.loadString(source) | |
} | |
} | |
val p = xml"""<person> |