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 Friends where | |
data Relation = Friend | Cousin | Professor deriving (Show, Eq) | |
data Person = Person String deriving (Show, Eq) | |
data Fact = Fact Relation (Person, Person) deriving (Show, Eq) | |
data Graph = Graph [Fact] deriving Show | |
areFriends :: Graph -> Person -> Person -> Bool | |
areFriends (Graph facts) person1 person2 = | |
(not . null) [(p1, p2) | Fact Friend (p1, p2) <- facts, p1 == person1 && p2 == person2] |
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 Reco where | |
import Prelude hiding (product) | |
import qualified Data.Set as Set | |
import Data.Set(Set) | |
import qualified Data.Map as Map | |
import Data.Map(Map) | |
import Data.List(sortBy) | |
import Data.Ord (comparing) |
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 QuasiQuotes #-} | |
{-# LANGUAGE OverloadedStrings #-} | |
module Main where | |
import Data.List (intercalate) | |
import Data.Maybe (fromMaybe) | |
import Network.HTTP.Conduit (simpleHttp) | |
import Control.Concurrent.Async (mapConcurrently) |
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
var events = ko.mapping.fromJS([]); | |
ko.applyBindings({ | |
events: events, | |
onRowClicked: function (row) { | |
// modify model to update UI. Will be re-updated by next ajax call :P | |
row.actor.login("FOO"); | |
} | |
}); |
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Gists</title> | |
<link type="text/css" rel="stylesheet" href="style.css"> | |
<script type='text/javascript' src='lib/zepto.min.js'></script> | |
<script type='text/javascript' src='lib/knockout-2.3.0.js'></script> | |
<script type='text/javascript' src='lib/knockout.mapping-latest.js'></script> | |
</head> |
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 FilterTree where | |
import Data.Maybe (mapMaybe) | |
data Tree a b = Leaf a | |
| Node a [Tree a b] | |
deriving Show | |
filterTree :: (a -> Bool) -> Tree a b -> Maybe (Tree a b) | |
filterTree p tree = |
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, MultiParamTypeClasses #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
module Json where | |
import Test.SmallCheck.Series | |
import GHC.Generics | |
import Data.List (intercalate) | |
import qualified Text.ParserCombinators.Parsec.Token as Token |
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, MultiParamTypeClasses #-} | |
{-# LANGUAGE DeriveGeneric #-} | |
module Polynomial where | |
import Test.SmallCheck.Series (Serial) | |
import GHC.Generics (Generic) | |
import qualified Text.ParserCombinators.Parsec as Parsec | |
import Text.ParserCombinators.Parsec (ParseError, Parser, sepBy1) |
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 Control.Category ((>>>)) | |
let io h = interact $ (++"\n") . show . h | |
let maplines h = map (h . words) . lines | |
let to_float = read :: String -> Float | |
let nth = flip (!!) | |
let (|>) = (>>>) :: (a -> b) -> (b -> c) -> (a -> c) |
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 Network (withSocketsDo, accept, listenOn, PortID(PortNumber)) | |
import Control.Concurrent (forkIO) | |
import System.IO (Handle, hClose, hGetLine, hSetBuffering, BufferMode (..)) | |
import Control.Applicative ((<$>), (<*>)) | |
import Control.Monad (forever) | |
import Control.Monad.STM (atomically) | |
import Control.Concurrent.STM (STM) | |
import Control.Concurrent.STM.TChan (TChan, newTChan, writeTChan, readTChan) | |
import Control.Concurrent.STM.TVar (TVar, newTVar, writeTVar, readTVar) | |
import Control.Concurrent.STM.SSem (SSem) |