Skip to content

Instantly share code, notes, and snippets.

View dyokomizo's full-sized avatar

Daniel Yokomizo dyokomizo

View GitHub Profile
@dyokomizo
dyokomizo / formats
Created September 24, 2014 15:33
Bookmark collection of serialization formats (and somewhat related stuff)
<DT><H3 ADD_DATE="1390495188" LAST_MODIFIED="1411568985">formats</H3>
<DL><p>
<DT><A HREF="http://swannodette.github.io/2014/07/23/a-closer-look-at-transit/" ADD_DATE="1406235975">A Closer Look at Transit</A>
<DT><A HREF="http://ocharles.org.uk/blog/posts/2014-06-10-reversible-serialization.html" ADD_DATE="1403296256">A Category for Correct-By-Construction Serializers and Deserializers</A>
<DT><A HREF="http://tools.ietf.org/html/draft-alakuijala-brotli-01" ADD_DATE="1402837786" ICON="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAl0lEQVQ4jaVSwRHEIAhcb64jUpPWRGqCmrhHlJMkPhJ2xoFZdIXVYmaGBD6ZwwDwHYm2LRSI5cIBAFUGiP6ETZBKJpVsyYkcuYjXn43Qb9a9OZX24JmA6tFIZafKeMa3JrrAW6Q9KFIp1UF+hGHUHMdyvrsPVZz3XzwglhCB/nFUwwfyDma1FYgFurcgGgTuCqvOZmjb8ANXSXxE46FkwQAAAABJRU5ErkJggg==">draft-alakuijala-brotli-01 - Brotli Compressed Data Format</A>
<DT><A HREF="https://github.com/JonathanSalwan/binary-sa
@dyokomizo
dyokomizo / Fix.hs
Last active January 3, 2016 09:39
module Fix where
left :: a -> (a -> c) -> (b -> c) -> c
left a l r = l a
right :: b -> (a -> c) -> (b -> c) -> c
right b l r = r b
fix f a = f a (fix f) id
We have three data types:
- Name and Password, both with String representations;
- Account, a Name and Password pair.
Given that each data type can have its invariants, we have some functions, representing morphisms from the data type to its representation (M is some Monad, like Maybe/Either/Validation, it's not important which):
- stringToName :: String -> M Name
- nameToString :: Name -> String
# Bottom-up Type Annotation with the Cofree Comonad
How do we add extra information to a tree? This has been called [The
AST Typing
Problem](http://blog.ezyang.com/2013/05/the-ast-typing-problem/).
After being hit with this problem in Roy's new type-inference engine,
I tried figuring out how to represent the algorithm. I eventually
realised that it looked like a comonadic operation. Turns out it's
been done before but I couldn't find any complete example.
@dyokomizo
dyokomizo / Glob.hs
Created November 26, 2012 13:05
Glob in Haskell
{-# LANGUAGE EmptyDataDecls, GADTs #-}
module Glob where
data L -- Witness for globs that begin/end with a literal
data S -- Witness for globs that begin/end with a star
data Glob a b e where -- Globs over [a] that begin with b and end with e
L :: [a] -> Glob a L L -- Literal glob
S :: Glob a S S -- Star glob
@dyokomizo
dyokomizo / Coinduction.hs
Created October 13, 2012 23:07 — forked from jonsterling/Coinduction.hs
Idea for codata syntax in Haskell
-- Inspired by http://www2.tcs.ifi.lmu.de/~abel/popl13.pdf
[codata|
codata Stream a where
head :: Stream a -> a
tail :: Stream a -> Stream a
|]
fib :: Stream Nat
[copattern|
@dyokomizo
dyokomizo / TypeClass.hs
Created October 11, 2012 12:15 — forked from tonymorris/TypeClass.hs
Type-class hierarchy
{-# LANGUAGE NoImplicitPrelude, MultiParamTypeClasses, Rank2Types, TypeOperators #-}
newtype Id a =
Id a
data a :\/ b =
Left a
| Right b
data a :/\ b =
@dyokomizo
dyokomizo / FakeWebFramework.hs
Created October 2, 2012 11:00 — forked from liamoc/FakeWebFramework.hs
Fake Haskell routing DSL
{-# LANGUAGE GADTs, KindSignatures #-}
module FakeWebFramework (add , notActuallyAWebFramework, get, Handler', link) where
import UrlPath
import Control.Monad.Writer
import Data.Maybe
maybeRead :: (Read a) => String -> Maybe a
maybeRead s = case reads s of
[(x, "")] -> Just x
@dyokomizo
dyokomizo / latency.txt
Created July 16, 2012 18:59 — forked from jboner/latency.txt
Latency Numbers Every Programmer Should Know
Latency Comparison Numbers
--------------------------
L1 cache reference 0.5 ns
Branch mispredict 5 ns
L2 cache reference 7 ns 14x L1 cache
Mutex lock/unlock 25 ns
Main memory reference 100 ns 20x L2 cache, 200x L1 cache
Compress 1K bytes with Zippy 3,000 ns
Send 1K bytes over 1 Gbps network 10,000 ns 0.01 ms
Read 4K randomly from SSD* 150,000 ns 0.15 ms