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
{-# LANGUAGE TupleSections #-} | |
module Main where | |
-- see https://plus.google.com/u/0/105746006385940131491/posts/9Uev6KVRUgK for | |
-- context | |
-- what we essentially have is a non-associative operation (represented by | |
-- concatenation): | |
-- | |
-- ab = ba = c | |
-- bc = cb = a |
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
module Main where | |
import Data.Bits | |
{- Note that, once completely reduced according to the rules, | |
- the string will be homogeneous. If it did contain two different | |
- characters, there would be a place where two touched, and | |
- they could be reduced. | |
- | |
- In fact, the order in which the reductions are done doesn't really matter, |
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
{-# LANGUAGE RankNTypes #-} | |
module Temp where | |
type Yielding a b = (a, PassiveIterable a b) | |
data PassiveIterable a b = Yield (Yielding a b) | End b | |
type ActiveIterable a b c = PassiveCoiterable a b -> c | |
type Awaiting a b = a -> PassiveCoiterable a b | |
data PassiveCoiterable a b = Await (Awaiting a b) | Return b | |
type ActiveCoiterable a b c = PassiveIterable a b -> c |
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
class Rational(n: Int, d: Int) extends Ordered[Rational] { | |
require( d != 0 ) | |
private val g = Rational.gcd(n.abs, d.abs) | |
val numer: Int = n/g * d.signum | |
val denom: Int = d.abs/g | |
def this(n: Int) = this(n, 1) | |
override def toString = numer + (if (denom == 1) "" else ("/"+denom)) |
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
{-# LANGUAGE RankNTypes #-} | |
module ChurchList where | |
import Data.Monoid | |
import Prelude hiding (zipWith) | |
-- church encoding for pairs | |
newtype ChurchPair a b = CP { runCP :: forall c. (a -> b -> c) -> c } | |
comma :: a -> b -> ChurchPair a b |
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
module Main where | |
import qualified Data.List as L | |
import qualified Data.Vector.Unboxed.Safe as V | |
import Control.Monad (replicateM) | |
import System.Random (randomRIO) | |
import Criterion.Main | |
med :: String -> String -> Int | |
med s1 = V.last . V.ifoldl' scanS1 costs_i . V.fromList |
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
<html> | |
<head> | |
<style> | |
.container > div { | |
color: transparent; /* don't show the text-overflow content */ | |
overflow: hidden; | |
height: 1em; | |
width: 100%; | |
} | |
.container { |
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
<html> | |
<head> | |
<style> | |
.land:hover { fill: red; } | |
</style> | |
</head> | |
<body> | |
<!-- svg taken from http://upload.wikimedia.org/wikipedia/commons/f/f9/BlankMap-Africa.svg --> | |
<svg xmlns:cc="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" version="1.1" height="1000" width="1000"> | |
<metadata id="metadata24111"> |
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
{-# LANGUAGE TupleSections #-} | |
module Ringing where | |
import Data.List (group, sort, find, intercalate) | |
import Data.Maybe (catMaybes, fromJust) | |
data Edge = (Int -> Maybe Int) :> Node | |
data Node = Node { nid :: Int, exit :: Bool, edges :: [Edge] } | |
instance Eq Node where |
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
module SetTrie where | |
import Prelude hiding (lookup) | |
import Data.List (intercalate) | |
import Data.Set hiding (empty, insert, map, fromList) | |
import qualified Data.Set as S | |
data SetTrie k v = SetTrie { count :: Int, leaf :: Maybe v, branches :: [(k,SetTrie k v)] } | |
prefixThenIndent :: String -> [String] -> [String] |