Skip to content

Instantly share code, notes, and snippets.

@edofic
edofic / multi_dd.go
Created August 28, 2014 08:31
multi dd
package main
import (
"fmt"
"github.com/koofr/go-ioutils"
"io"
"os"
"sync"
)
@edofic
edofic / go_talk.go
Last active August 29, 2015 14:05
A short talk about golang written as pseudo-go
// GO(lang) is C
// .. with a bit different syntax
package main
import "fmt"
func main() {
fmt.Println("Hello World")
}
// and a much faster compiler
@edofic
edofic / singletonImplicitRestriction.scala
Created July 7, 2014 11:56
restricting types using smart constructors, implicits and singleton types
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 {
@edofic
edofic / copy.hs
Created July 2, 2014 09:44
file copy
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
@edofic
edofic / yoneda_cont.hs
Created July 1, 2014 11:27
Can ContT be implemented as a value? Something something Yoneda lemma.
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
@edofic
edofic / queue.hs
Created June 30, 2014 20:44
a simple FIFO
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 []
@edofic
edofic / flist.hs
Created June 28, 2014 10:03
composable function list
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
---------------------------------------------
up = (1:)
down = (-1:)
done = []
states = scanl (+) 0
minMaxEnd commands =
let s = states commands
in (minimum s, maximum s, last s)
@edofic
edofic / map.prolog
Last active August 29, 2015 14:02
hacky map(categorical functor) implementation in prolog
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]
@edofic
edofic / strict.hs
Created June 10, 2014 06:50
strict "monad" for haskell
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