(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
#!/bin/bash | |
### | |
### my-script — does one thing well | |
### | |
### Usage: | |
### my-script <input> <output> | |
### | |
### Options: | |
### <input> Input file to read. | |
### <output> Output file to write. Use '-' for stdout. |
(by @andrestaltz)
If you prefer to watch video tutorials with live-coding, then check out this series I recorded with the same contents as in this article: Egghead.io - Introduction to Reactive Programming.
Jag skäms inte över att vara svensk.
Men jag skäms över hur vissa ser ned på dem som vill bli svenskar.
Jag skäms inte över den svenska flaggan.
Men jag skäms över hur den används mot dem som vill hissa den.
Jag skäms inte över Sverige.
Men jag skäms över hur vissa anser sig ha ensamrätt till landet.
For binary trees I've found a variant of nested sets. | |
The idea is to let | |
- the root node be represented by the interval [0, 1], | |
- the two children of the root node be represented by the intervals [0, 1/2] and [1/2, 1] respectively, | |
- the grandchild nodes by [0, 1/4], [1/4, 1/2], [1/2, 3/4] and [3/4, 1]. | |
Then it's easy to find: | |
- the left and right children (one or both), | |
- all descendents of a node, |
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, IncoherentInstances #-} | |
class Cout a r where | |
(<<) :: IO String -> a -> IO r | |
instance Cout [Char] [Char] where | |
lm << x = fmap (++ x) lm | |
instance Cout [Char] () where | |
lm << x = lm >>= putStr . (++ x) |
import Control.Applicative | |
import Data.Functor.Constant | |
import Data.Generics.Multiplate | |
data ZigZag a b = ZNil | Zig a (ZigZag a b) | Zag b (ZigZag b a) | |
data ZigZagPlate a b f = ZigZagPlate | |
{ znilab :: f (ZigZag a b) | |
, zigab :: a -> ZigZag a b -> f (ZigZag a b) | |
, zagab :: b -> ZigZag b a -> f (ZigZag a b) |
{-# LANGUAGE GADTs, EmptyDataDecls, ExistentialQuantification #-} | |
module RBTree where | |
-- Node color | |
data Red | |
data Black | |
-- Node depth |
import Data.Word | |
freq = 0.3 | |
spread = 8.0 | |
unbase :: Integral int => int -> Word8 -> Word8 -> Word8 -> int | |
unbase base r g b = (fi r*base+fi g)*base+fi b | |
where fi = fromIntegral | |
-- | Approximate a 24-bit Rgb colour with a colour in the xterm256 6x6x6 colour cube, returning its index. |
-- static Peano constructors and numerals | |
data Zero | |
data Succ n | |
type One = Succ Zero | |
type Two = Succ One | |
type Three = Succ Two | |
type Four = Succ Three |
-- playing with the adaptive library. | |
import Control.Monad.Adaptive | |
printMod mod = do | |
r <- inCh $ readMod mod | |
inM (putStrLn $ show r) | |
main = run $ do | |
i1 <- newMod (return (2 :: Integer)) |