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
// Forked and modified from https://gist.github.com/DrBoolean/34c1d3651d1338b1b187 | |
const daggy = require('daggy') | |
const compose = (f, g) => x => f(g(x)) | |
const id = x => x | |
const kleisli_compose = (f, g) => x => f(x).flatMap(g) | |
//=============FREE============= | |
const Free = daggy.taggedSum({Suspend: ['x', 'f'], Pure: ['x']}) |
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
// Utility function for detecting generators. | |
let isGenerator = x => { | |
return Function.isGenerator && | |
Function.isGenerator.call(x) | |
} | |
// Data type represents channel into which values | |
// can be `put`, or `received` from. Channel is | |
// very much like queue where reads and writes are | |
// synchronized via continuation passing. |
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
import Data.IORef | |
main :: IO () | |
main = do | |
putStrLn "Create a mutable state 0." | |
ref <- newIORef (0 :: Int) | |
putStrLn "Increase by 1." | |
modifyIORef ref (+1) | |
result <- readIORef ref | |
print result |
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
readInt :: IO Int | |
readInt = readLn | |
main = do | |
print "Press any key to start:" | |
line <- getLine | |
print "Type the first integer x:" | |
x <- readInt | |
print "Type the second integer y:" | |
y <- readInt |
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
// Simulating Haskell typeclass with Java generic interface. | |
public class Main { | |
public static void main(String[] args) { | |
MyInt i1 = new MyInt(1); | |
MyInt i2 = new MyInt(2); | |
MyInt i3 = i1.add(i2); | |
System.out.println(i3); // "3" | |
MyString s1 = new MyString("1"); |
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
#!/usr/bin/python3.5 | |
# Author: Dagang Wei (github.com/weidagang) | |
# Created: 2016-11-19 | |
# Last modified: 2016-11-27 | |
# License: MIT | |
# Self link: https://gist.github.com/weidagang/1b001d0e55c4eff15ad34cc469fafb84 | |
# | |
# This code demonstrates the core algorithm for distributed MVCC based cross-row | |
# transactions. The algorithm is built on top of a distributed key-value database |
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
# In-memory MVCC transaction of read-committed isolation level. | |
next_xid = 1 | |
active_xids = set() | |
records = [] | |
def new_transaction(): | |
global next_xid | |
print('Txn %d: start' % next_xid) | |
xid = next_xid |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
% MATLAB code for finding the best fit line using least squares method. | |
% input in the form of matrix, each row is a (x, y). | |
input = [... | |
1, 2;... | |
2, 4.5;... | |
3, 5.9;... | |
4, 8.1;... | |
5, 9.8;... | |
6, 12.3]; |
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
Prelude> let ones = 1 : ones | |
Prelude> take 3 ones | |
[1,1,1] | |
Prelude> let lessThan x y = y < x | |
Prelude> takeWhile (lessThan 5) [1..] | |
[1,2,3,4] |
NewerOlder