This file contains 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
module Main where | |
import Control.Concurrent.Chan | |
import Control.Concurrent | |
-- A sieve that receives numbers from "inChan", filters | |
-- out the factors of "prime" and sends the results | |
-- out through "outChan". | |
sieve inChan outChan prime = do | |
print prime |
This file contains 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
primes = sieve [2..] | |
where | |
sieve (p:ps) = p : (sieve [n | n <- ps, n `mod` p /= 0]) |
This file contains 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
slowlyWriteList2Chan chan [] = do return () | |
slowlyWriteList2Chan chan (n:ns) = do | |
writeChan chan n | |
yield -- Magic happens with this line! | |
slowlyWriteList2Chan chan ns |
This file contains 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
define m 10 | |
define this-better-be-6 (add 1 2 3) | |
define this-better-be-0 add() | |
define five() 5 | |
define (trpl x) (add x x x) | |
define (g a b c) (add a b c) | |
define (d/dx f) | |
define delta 0.001 |
This file contains 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
(define m 10) | |
(define this-better-be-6 | |
(add 1 2 3)) | |
(define this-better-be-0 | |
(add)) | |
(define (five) 5) |
This file contains 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
// f(N) is run a few times, timed and some stats are | |
// returned as an object. | |
function timeit(f, N) { | |
var start, stop, dt; | |
var worst = 0, best = 1000 * 3600, mean = 0, sigma = 0; | |
var i, M = 7; | |
for (i = 0; i < M; ++i) { | |
start = Date.now(); | |
f(N); | |
stop = Date.now(); |
This file contains 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 f1(N) { | |
var i, sum = 0; | |
for (i = 0; i < N; ++i) { | |
sum += Math.sin(i); | |
} | |
return sum; | |
} | |
function f2(f) { | |
return function (N) { |
This file contains 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 timeit(f, N, S) { | |
var start, timeTaken; | |
var stats = {min: 1e50, max: 0, N: 0, sum: 0, sqsum: 0}; | |
var i; | |
for (i = 0; i < S; ++i) { | |
start = Date.now(); | |
f(N); | |
timeTaken = Date.now() - start; |
This file contains 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 watch = (function () { | |
// A task queue for calling tasks asynchronously. | |
// Note that one task queue processes all the notification | |
// callbacks for all installed watchers. This allows | |
// the use of lots of watchers without incurring a | |
// corresponding increase in setTimeouts. If we | |
// did each notification in its own timer callback, | |
// then we might incur unwanted delays between |
This file contains 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
// There is a recent Hacker News thread discussing Python | |
// creator Guido van Rossum's objections to a callback | |
// based API, based on its poor ability to work with | |
// exceptions. (http://news.ycombinator.com/item?id=3750817) | |
// | |
// Since Node.js and much of web stuff deals with callbacks | |
// ... a lot, I thought it might be possible to address that concern | |
// using a simple, flexible sequencing function. Here is my take | |
// on it - | |
// |
OlderNewer