An example of how an (Erlang inspired) distributed actor framework could work in Node.js.
Start slave nodes.
$ node example.js slave localhost:3000 &
$ node example.js slave localhost:3001 &
module Main where | |
import Control.Concurrent (forkIO, threadDelay) | |
import Control.Exception (catch, IOException(..)) | |
import Numeric (showHex) | |
import Network (accept, listenOn, PortID(PortNumber)) | |
import System.IO (hClose, hPutStr, hSetBuffering, BufferMode(NoBuffering)) | |
import System.Environment (getArgs) | |
size = 10 * (1024 ^ 3) -- gigabyte multiplier |
import language.higherKinds | |
import language.implicitConversions | |
object Main { | |
trait Functor[F[_]] { | |
def map[A,B](fa: F[A])(f: A => B): F[B] | |
} | |
trait Monad[F[_]] extends Functor[F] { |
package com.twitter.finagle.actor | |
import com.twitter.concurrent.AsyncQueue | |
import com.twitter.util.Future | |
trait Actor[A] extends (A => Future[Unit]) { | |
val mailbox = new AsyncQueue[Any] | |
def send(msg: Any) = mailbox.offer(msg) | |
def receive = mailbox.poll | |
} |
import scala.concurrent._ | |
import ExecutionContext.Implicits.global | |
import scala.util.parsing.combinator._ | |
import scala.util.matching.Regex | |
object Scout { | |
object UrlParser extends RegexParsers { | |
def digits: Parser[Int] = """-?\d+""".r ^^ (_.toInt) | |
} |
object Main { | |
case class NFA[Q,S]( | |
initialState: Q, | |
isAccepting: Q => Boolean, | |
transition: (Q, S) => Seq[Q] | |
) | |
// foldM specialized for Seq | |
def foldM[A,B](f: (A,B) => Seq[A], a: A, b: Seq[B]): Seq[A] = b match { | |
case Nil => Seq(a) |
import java.io.{File, PrintWriter} | |
import scala.language.higherKinds | |
object Main { | |
type Logger = String => Unit | |
def nullLogger(msg: String) { } | |
def stdErrLogger(msg: String) { | |
System.err.println(msg) |
See: 06b3e824c.
Add fromIntegral
to convert GHC.Int.Int32
to Int
.
HaskellServer.hs:73:60:
Couldn't match type GHC.Int.Int32'
Expected type: Maybe GHC.Int.Int32
Actual type: Maybe Int
In the ($)', namely
Data.Text.Lazy.Internal.Text'
module Main where | |
import Control.Arrow ((>>>), second) | |
import Control.Concurrent (forkFinally) | |
import Control.Concurrent.MVar (newMVar, modifyMVar_, readMVar) | |
import Network (connectTo, HostName, PortID(..), withSocketsDo) | |
import System.Environment (getArgs) | |
import System.IO (Handle, hClose, hGetContents, hPutStrLn) | |
toAddr :: String -> (HostName, PortID) |
if (typeof Image == "undefined") { | |
var Image = (function() { | |
function Image() { } | |
Image.prototype.addEventListener = function(name, fn, bubble) { | |
setTimeout(function() { if (name === "load") { fn(); } }, 0); | |
}; | |
return Image; | |
})(); | |
} |