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 main | |
import ( | |
"fmt" | |
"github.com/koofr/go-ioutils" | |
"io" | |
"os" | |
"sync" | |
) |
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
// GO(lang) is C | |
// .. with a bit different syntax | |
package main | |
import "fmt" | |
func main() { | |
fmt.Println("Hello World") | |
} | |
// and a much faster compiler |
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
type Tag[A] = { type Tag = A } | |
type Safe[A, B] = A with Tag[B] | |
def safe[A <: AnyRef](a: A) = a.asInstanceOf[Safe[A, a.type]] | |
////////////////////////// | |
type Restricted = String | |
object Restricted { |
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
module Main where | |
import System.Environment (getArgs) | |
import System.IO (withFile, Handle, IOMode(ReadMode, WriteMode)) | |
import Data.ByteString as BS | |
blockSize :: Int | |
blockSize = 32 * 1024 |
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
import Control.Applicative | |
import Control.Monad.Cont.Class | |
newtype ContT m r a = ContT { unCont :: m a } | |
runCont :: (Monad m) => ContT m r a -> (a -> m r) -> m r | |
runCont (ContT a) f = a >>= f | |
instance (Functor m) => Functor (ContT m r) where | |
fmap f (ContT ma) = ContT $ fmap f ma |
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 Queue a = Queue [a] [a] deriving (Eq) | |
toList :: Queue a -> [a] | |
toList (Queue front back) = front ++ reverse back | |
empty :: Queue a | |
empty = Queue [] [] | |
fromList :: [a] -> Queue a | |
fromList xs = Queue xs [] |
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 FList c a b where | |
Cons :: c a x -> FList c x b -> FList c a b | |
Nil :: FList c a a | |
compose :: FList (->) a b -> a -> b | |
compose Nil = id | |
compose (Cons g fl) = compose fl . g | |
--------------------------------------------- |
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
up = (1:) | |
down = (-1:) | |
done = [] | |
states = scanl (+) 0 | |
minMaxEnd commands = | |
let s = states commands | |
in (minimum s, maximum s, last s) |
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
map(_, [], []). | |
map(F, [X|XS], [Y|YS]) :- | |
G =.. [F, X, Y], G, | |
map(F, XS, YS). | |
add_one(X, Y) :- Y is X + 1. | |
/* | |
?- smap(add_one, [1,2,3], R). | |
R = [2,3,4] |
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
import Control.Applicative | |
import Debug.Trace (trace) | |
data Strict a = Strict { runStrict :: {-# UNPACK #-} !a } deriving (Eq, Show, Functor) | |
instance Applicative Strict where | |
pure = Strict | |
Strict f <*> Strict a = Strict $ f a | |
instance Monad Strict where |