Skip to content

Instantly share code, notes, and snippets.

@lagondo
lagondo / gist:9351941
Created March 4, 2014 17:54
Bacon.js and Hammer.js
hammerStream = (element, event, opts = {}) ->
Bacon.fromBinder (sink) ->
push = (event) -> sink event
Hammer(element, opts).on event, push
-> Hammer(element, opts).off event, push
data Axis = X | Y | Z
data Cube f = Cube { front, back, left, right, top, bottom :: f }
rotate90 :: Axis -> Cube f -> Cube f
rotate90 X c = c { front = bottom c
, back = top c
, top = front c
, bottom = back c }
rotate90 Y c = c { left = back c
instance Rotational (Cube f) where
rotate90 X c = c { front = bottom c
, back = top c
, top = front c
, bottom = back c }
rotate90 Y c = c { left = back c
, front = left c
, right = front c
, back = right c }
rotate90 Z c = c { top = left c
module WhatWhat
( lol
, cat
) where
lol = 1
cat = 2
coc = 3
suc = 4
@lagondo
lagondo / gist:1548618
Created January 1, 2012 23:15
Miten funktio on funktori Haskellissa?

Miten funktio on funktori Haskellissa?

Alla on kirjoitettu auki Learnyouahaskell.comin Functors redux -osiota.

Funktiotyypit

Haskellissa funktiotyyppejä luodaan tyyppikonstruktorilla (->) t1 t2 eli infix-notaatiolla t1 -> t2. Kun kiinnitetään ensimmäinen tyyppiparametri t1, saadaan tyyppikonstruktori (->) t1, joka ottaa vielä täsmälleen yhden tyyppiparametrin.

Funktio funktoriksi

import Data.Char
main = print (filter isUpperOrLower chars) where
chars = "123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz"
oegy combinator fs x = foldl1 combinator (map ($ x) fs)
isUpperOrLower = oegy (||) [isUpper, isLower, isDigit]
import Data.Char
main = print (filter isUpperOrLower chars) where
chars = "123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz"
oegy combinator f1 f2 x = combinator (f1 x) (f2 x)
isUpperOrLower = oegy (||) isUpper isLower
import Control.Monad
data Tree a = Empty | Leaf a | Node (Tree a) a (Tree a) deriving Show
jakub = Node (Node (Leaf "Pentti")
"Jorma"
(Leaf "Maija"))
"Jakub"
(Node (Leaf "Jozef")
"Teresa"
main = do putStrLn "I need your clothes, boots and SSN:"
ssn <- getLine
putStrLn (show (isSSN ssn))
isSSN ssn = True
main = do putStrLn "I need your clothes, boots and SSN:"
ssn <- getLine
putStrLn $ show $ isSSN ssn
isSSN ssn = True