This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package bintree | |
import org.scalatest.{FlatSpec, Matchers} | |
import scalaz.Free.Trampoline | |
import scalaz.{-\/, Free, Functor, Trampoline, \/-} | |
object tree { | |
case class Pair[A](l:A, r:A) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes, MultiParamTypeClasses, FunctionalDependencies, FlexibleContexts, FlexibleInstances, UndecidableInstances, DeriveFunctor #-} | |
import Prelude hiding (abs) | |
import Control.Monad | |
-- Free -- | |
data Free f a = Pure a | Wrap (f (Free f a)) | |
instance (Show (f (Free f a)), Show a) => Show (Free f a) where |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data Cont u a | |
= Cont (GenHaxl u a) | |
| forall b. Cont u b :>>= (b -> GenHaxl u a) | |
| forall b. (Cont u (b -> a)) :<*> (Cont u b) | |
| forall b. (b -> a) :<$> (Cont u b) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
instance Monad Fetch where | |
return a = Fetch $ \ref -> return (Done a) | |
Fetch m >>= k = Fetch $ \ref -> do | |
r <- m ref | |
case r of | |
Done a -> unFetch (k a) ref | |
Blocked br c -> return (Blocked br (c >>= k)) | |
Throw e -> return (Throw e) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.on('message', function(message) { | |
console.log("message received", message); | |
process.send(message.toUpperCase(), function(err) { | |
console.log("replied"); | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ant = function *(s = "1") { | |
yield s; | |
yield* ant(s.replace(/(.)\1?\1?/g, g => g.length + g[0])); | |
} | |
for (var i=0, a = ant(); i++<10; ) { | |
console.log(a.next().value) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @template T, S | |
* @param {[T]} items | |
* @param {function(T):Promise<S>} f | |
* @return {Promise<[S]>} | |
*/ | |
function traverse(items, f) { | |
if (items.length == 0) { | |
return Promise.resolve([]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var csp = require("js-csp"); | |
function Init() { | |
return csp.go(function* () { | |
return 1; | |
}); | |
} | |
function Next(i) { | |
var out = csp.chan(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function* Init() { | |
yield 1; | |
} | |
function* Next(it) { | |
var prev = it.next().value; | |
var count = 1; | |
for (let n of it) { | |
if (n == prev) { | |
count++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process.on('message', function(message) { | |
console.log("message received", message); | |
process.send(message.toUpperCase(), function(err) { | |
console.log("replied",err); | |
}); | |
}); |