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
-- Wrapper for recursive types | |
data Fix f = In { out :: f (Fix f) } | |
-- 1-layer fold and unfold | |
type Algebra f a = f a -> a | |
type Coalgebra f a = a -> f a | |
cata :: Functor f => Algebra f b -> Fix f -> b | |
ana :: Functor f => Coalgebra f a -> a -> Fix f |
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
def split(list): | |
"[a] -> (a, [a])" | |
return [list[0], list[1:]] | |
def reduce(list, zero, add): | |
"([a], b, (b, a) -> b) -> b" | |
for i in range(0, len(list)): | |
zero = add(zero, list[i]) |
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 | |
TemplateHaskell, | |
Rank2Types, | |
NoMonomorphismRestriction, | |
TypeOperators, | |
StandaloneDeriving, | |
DeriveFunctor #-} | |
import Control.Applicative |
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
--module MyZipper | |
-- ( File() | |
-- , Position | |
-- , up | |
-- , downAtLeft | |
-- , downAtRight | |
-- , left | |
-- , right | |
-- , comeIn |
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 (permutations) | |
import Control.Monad (guard) | |
main = putStrLn $ head solutions | |
solutions = do | |
let range = [0.. 9] | |
[s,e,n,d,m,o,r,y,_,_] <- permutations range |
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 (sortBy) | |
import Data.Function (on) | |
merge :: [(Int, a)] -> [(Int, b)] -> [(Maybe a, Maybe b)] | |
merge az bz = case (az, bz) of | |
((i, a) : az', (j, b) : bz') -> | |
case i `compare` j of | |
LT -> (Just a, Nothing) : merge az' bz | |
EQ -> (Just a, Just b) : merge az' bz |
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 (foldl') | |
avg list = | |
let (count, sum) = foldl' collect (0, 0) list | |
in fromIntegral sum / count | |
where | |
collect (count, sum) item = | |
count `seq` |
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
def list_induction list, stop, step, ret | |
return stop.(ret) if list.empty? | |
x = list.shift | |
return list_induction list, stop, step, -> (args) { | |
step.(x, args, ret) | |
} | |
end | |
list_induction [1,2,3,4,5], |
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
:- op(1030, xfx, is). | |
:- op(1045, yfx, @). | |
:- op(1040, yfx, after). | |
:- op(1050, xfy, to). | |
:- op(1175, xfy, in). | |
compile | |
--> simplify | |
, toJS | |
, ! |
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 Color exposing (..) | |
import Dict exposing (..) | |
import Graphics.Element exposing (..) | |
import Graphics.Collage exposing (..) | |
import Keyboard exposing (..) | |
import Maybe exposing (..) | |
import Signal exposing (..) | |
type alias Game = | |
{ player : Point |