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
;; lovingly stolen from SICP | |
;; http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-14.html#%_sec_2.1.3 | |
(define (my-cons x y) | |
(lambda (m) (m x y))) | |
(define (my-car z) | |
(z (lambda (p q) p))) | |
(define (my-cdr z) |
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 DeriveFunctor #-} | |
{-# LANGUAGE GeneralizedNewtypeDeriving #-} | |
import Prelude hiding (not,and,log) | |
import Control.Monad | |
import Control.Monad.State | |
import Control.Monad.Free | |
import Control.Monad.Trans | |
import Control.Monad.Writer | |
import qualified Data.Vector.Unboxed as U |
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
{- | |
- Usage: ./nap [INT] | |
- [INT] is some positive integer (eg 1, 2, etc) | |
-} | |
import System.Environment (getArgs) | |
import Control.Applicative ((<$>), (<*>), pure) | |
circadian = 21.83 |
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 add (λ (n) | |
(λ (m) | |
(λ (f) | |
(λ (x) | |
((n f) ((m f) x))))))) | |
(define mult (λ (n) | |
(λ (m) | |
(λ (f) | |
(n (m f)))))) |
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
How to add imperative programming to a pure functional language | |
=== | |
Many people bemoan languages such as Haskell for not supporting imperative | |
programming; they decry the need for math in their computer science. | |
![Math? In my computer? Yeah right.](http://i.imgur.com/YDIaEPB.jpg) | |
I'm here to tell you that not only does Haskell make imperative programming a | |
cinch, but safe and correct as well. Follow along! This post is written in |
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 ] |