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
nonEmptySubsequences = foldr comb [] | |
where comb x xs = xs ++ fmap (x:) ([]:xs) | |
findSum p = filter (p.sum) . nonEmptySubsequences | |
hasSum p = not.null . findSum p | |
-- Trying it in the REPL |
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
-- | Experimental and very simple quasi-quotation of ECMAScript in | |
-- Haskell. Doesn't support anti-quotation as of now. | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
module Language.ECMAScript5.Syntax.QuasiQuote (js, jsexpr, jsstmt) where | |
import qualified Language.Haskell.TH as TH | |
import Language.Haskell.TH.Quote | |
import Text.Parsec hiding (parse) |
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
-- | Experimental and very simple quasi-quotation of ECMAScript in | |
-- Haskell. Doesn't support anti-quotation as of now. | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE Rank2Types #-} | |
module Language.ECMAScript5.Syntax.QuasiQuote (js, jsexpr, jsstmt) where | |
import qualified Language.Haskell.TH as TH | |
import Language.Haskell.TH.Quote |
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
#include <stdio.h> | |
int main(void) { | |
int n, e, i = 0; | |
scanf("%d\n", &n); | |
scanf("%d", &e); | |
int sum = e, first = e, last = e, len = 1; | |
int delta; | |
while (++i < n) { | |
scanf(" %d", &e); |
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
import functools | |
def scanl(f,x,it): | |
return functools.reduce(lambda xs, y: xs + [f(xs[-1],y)], it, [x]) | |
def scanl1(f, it): | |
return scanl(f, it[0], it[1:]) | |
def scanr1(f, it): | |
return reversed(scanl1(f, list(reversed(it)))) |
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
import Text.Parsec | |
import Control.Applicative hiding ((<|>)) | |
import qualified Data.Map as M | |
import Data.Either (partitionEithers) | |
import Data.List (intercalate) | |
import System.IO (hPutStrLn, stderr) | |
data Word = Splice String | Word String | |
deriving (Ord, Eq, Show) |
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
import Control.Monad (void) | |
import Control.Applicative | |
import Data.Foldable (for_) | |
import Data.Monoid | |
import Text.Printf | |
data Attributed m w a = Attributed (m a) w | |
instance Functor m => Functor (Attributed m w) where | |
fmap f (Attributed m w) = Attributed (fmap f m) w |
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
import System.Random | |
import Control.Monad | |
count = length . filter id | |
avenge = do | |
x <- replicateM 8 randomIO | |
return $ count x <= 4 | |
test n = do |
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
data Pair a = Pair a a | |
data Exp typ where | |
Vec :: Exp a -> Exp a -> Exp (Pair a) | |
Const :: Int -> Exp Int | |
-- with type | |
type RHS typ = String |
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
vShader :: SC.Shader GLfloat | |
vShader = do | |
pos <- attribute vec3 "position" | |
a_color <- attribute vec3 "a_color" | |
color <- varying vec3 "color" | |
gl_Position =: pos .: 1 | |
color =: pos | |
fShader :: SC.Shader GLfloat |
OlderNewer