This file contains hidden or 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 QuantifiedConstraints #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE DataKinds #-} | |
import GHC.Exts | |
type family AllAllowed k xs where | |
AllAllowed k '[] = () | |
AllAllowed k (x : xs) = (Allowed k x, AllAllowed k xs) |
This file contains hidden or 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
\xs -> sum $ map (sum . toDigits) xs | |
= { f $ x = f x } | |
\xs -> sum (map (sum . toDigits) xs) | |
= { function application associates to the left } | |
\xs -> sum ((map (sum . toDigits)) xs) | |
= { (f . g) x = f (g x), with f = sum, g = (map (sum . toDigits)) } | |
\xs -> (sum . (map (sum . toDigits))) xs | |
= { eta reduction } | |
(sum . (map (sum . toDigits))) | |
= { remove unnecessary clarifying parentheses } |
This file contains hidden or 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 TypeFamilies #-} | |
class Foo a where | |
type I a t | |
foo :: I a t -> t -> a | |
instance Foo () where | |
type I () t = () | |
foo _ _ = () | |
instance Foo b => Foo (a, b) where |
This file contains hidden or 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
#!/bin/zsh | |
set -e | |
setopt null_glob | |
case $# in | |
1) true;; | |
*) | |
echo Usage: ghc-version VERSION | |
ghc --version || true |
This file contains hidden or 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 FlexibleInstances #-} | |
import Data.Functor.Compose | |
import Control.Monad | |
joinEntry :: Maybe [Maybe [a]] -> Maybe [a] | |
joinEntry = fmap join . join . fmap sequenceA | |
instance Monad (Compose Maybe []) where | |
-- or use liberal applications of coerce to avoid the calls to Compose and getCompose | |
x >>= f = Compose . joinEntry . getCompose . fmap (getCompose . f) $ x |
This file contains hidden or 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 Stream | |
def initialize(&more) | |
@sofar = [] | |
@more = more | |
end | |
def [](i) | |
while i >= @sofar.length do | |
@sofar += @more.call(@sofar) | |
end |
This file contains hidden or 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
-- dmwit style | |
module Parser where | |
import Data.Time | |
data Transaction = Transaction | |
{ amount :: Double | |
, time :: UTCTime | |
, tags :: [String] |
This file contains hidden or 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 <unistd.h> | |
int main() { | |
char *args[3] = {"notsleep", "10", NULL}; | |
return execv("/usr/bin/sleep", args); | |
} |
This file contains hidden or 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 Data.List | |
import System.Environment | |
data SizedTree a = Node Integer a [SizedTree a] deriving (Eq, Ord, Read, Show) | |
type Stream a = [SizedTree a] | |
indexT :: Integer -> SizedTree a -> a | |
indexT 0 (Node _ v _) = v | |
indexT n (Node _ _ vs) = indexS (n-1) vs |
This file contains hidden or 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 Data.List | |
import System.Environment | |
data SizedTree a = Node Integer a [SizedTree a] deriving (Eq, Ord, Read, Show) | |
type Stream a = [SizedTree a] | |
indexT :: Integer -> SizedTree a -> a | |
indexT 0 (Node _ v _) = v | |
indexT n (Node _ _ vs) = indexS (n-1) vs |