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 r5rs | |
; Composable syntax-rules macros via the CK abstract machine | |
; | |
; We demonstrate (mutually-) recursive, higher-order applicative | |
; macros with clausal definitions, defined in the style that looks very | |
; much like that of ML or (strict) Haskell. | |
; We write composable, call-by-value--like macros without | |
; resorting to the continuation-passing-style and thus requiring no | |
; macro-level lambda. The syntax remains direct-style, with | |
; nested applications. |
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
#!/usr/bin/env bash | |
### | |
# Usage | |
### | |
# twitch <path-to-file> | |
PATH_TO_TWITCH_KEY="$HOME/.config/twitch.key" | |
if [ ! -f "$HOME/.config/twitch.key" ]; then | |
echo "Please write your twitch key to $PATH_TO_TWITCH_KEY" |
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
{- | | |
Operational transformation in Haskell using (co)free (co)monads. | |
-} | |
{-# LANGUAGE DeriveFunctor #-} | |
{-# LANGUAGE MultiParamTypeClasses #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
import Data.List (splitAt) | |
import Control.Monad |
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
class cont: | |
def __init__(self, fn): | |
self.fn = fn | |
def __call__(self, *args, **kwargs): | |
return (lambda: self.fn(*args, self, **kwargs)) | |
class tailrec: |
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 DeriveFoldable #-} | |
{-# LANGUAGE DeriveTraversable #-} | |
{-# LANGUAGE StandaloneDeriving #-} | |
{-# LANGUAGE TypeFamilies #-} | |
{-# LANGUAGE DataKinds #-} | |
{-# LANGUAGE TypeOperators #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE FlexibleContexts #-} | |
{-# LANGUAGE FlexibleInstances #-} |
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
/* Helper function which writes a string to a file descriptor. | |
*/ | |
static gboolean | |
write_to_fd (int fd, const gchar *message) { | |
gsize bw; | |
GIOChannel *channel = g_io_channel_unix_new (fd); | |
GString *message_str = g_string_new (message); | |
g_string_append (message_str, "\n"); | |
g_io_channel_write_chars (channel, | |
message_str->str, |
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
It's said that all Haskell programmers eventually write a blog post explaining | |
Monads. Today I fulfill my destiny. The basic format is ripped from "Learn You A | |
Haskell For Great Good," but these are my own crappy examples. | |
This blog post is literate Haskell; you can get it | |
[here](https://gist.github.com/4145341). You can import it into ghci and type | |
the functions to see their output (`ghci monads.lhs`). For this to work, we'll | |
need to import one module for use later: | |
> import Control.Applicative |
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 #-} | |
import Control.Applicative | |
import Control.Comonad | |
import Control.Monad (forM_) | |
-- These two typeclasses probably make some people groan. | |
class LeftRight t where | |
left :: t a -> t 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
Writing a billing system in Haskell, using Stripe and Heroku | |
=== | |
*This post is written in literate Haskell, meaning the source can be turned | |
into a blogpost or a working program. You can view the [source][source]. | |
[source]: https://gist.github.com/gatlin/7754289 | |
Normally clients pay me with checks, but recently one informed me that they | |
really really really like *really really* super prefer some kind of online |
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 #-} | |
import Prelude hiding (IO, getLine) | |
import qualified Prelude as P | |
import System.IO.Unsafe | |
-- * The Foreign Function Interface | |
-- | FFI values permit interfacing with foreign functions, such as low-level IO | |
-- operations, memory management operations, or bindings to other user-level |