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
#lang racket | |
; simple cons pairs | |
(define (my-cons fst snd) | |
(λ (f) (f fst snd))) | |
(define (my-first c) | |
(c (λ (a b) a))) | |
(define (my-second c) |
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
(define True (λ () (λ (a b) (a)))) | |
(define False (λ () (λ (a b) (b)))) |
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
{-# LANGUAGE OverloadedStrings #-} | |
import Network.MPD | |
import Control.Concurrent.Timer | |
import Control.Concurrent.Suspend.Lifted | |
import System.Environment | |
startTimer seconds = oneShotTimer (withMPD (play Nothing) >> return ()) (sDelay (fromInteger seconds)) |
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
def tail_rec(fun): | |
''' | |
Receive a function `fun` as an argument; | |
Return a function which accepts `fun` and runs it in a loop. | |
''' | |
def tail(fun): | |
a = fun | |
while callable(a): | |
a = a() | |
return a |
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
{-# LANGUAGE MonadComprehensions #-} | |
-- From https://bmark.us/bmark/readable/060063d3dd0330 | |
import Data.Monoid ((<>)) | |
import Data.Maybe (fromMaybe) | |
import Control.Monad (mapM_) | |
fizzbuzz x = fromMaybe (show x) $ [ "fizz" | x `rem` 3 == 0 ] | |
<> [ "buzz" | x `rem` 5 == 0 ] |
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
{-# LANGUAGE RankNTypes #-} | |
data F f = F { | |
_map :: forall a b. (a -> b) -> f a -> f b | |
} | |
data Mu f a | |
= Term { retract :: a } | |
| Cont (f (Mu f a)) |
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
{- | THIS HAS MOVED | |
- | |
- https://github.com/gatlin/FreeStream | |
-} |
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
Type operators! | |
=== | |
Turns out a GHC language extension makes a lot of cool things possible that I | |
think you hinted at: | |
> {-# LANGUAGE TypeOperators #-} | |
> data a + b = Inl a | Inr b deriving 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
var getId = function() { | |
var _id = 0; | |
return function() { | |
return _id++; | |
} | |
}() | |
// usage | |
console.log(getId()); |
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
/*** | |
* Fun with closures! | |
* | |
* Run this with node.js: | |
* | |
* $> node closurewanking.js | |
*/ | |
var http = require('http'); |
OlderNewer