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 GeneralizedNewtypeDeriving #-} | |
import Data.Map.Strict (Map) | |
import qualified Data.Map.Strict as M | |
import MonadLib | |
type Tables t a = (PrefixMap t a, InfixMap t a) | |
newtype PrattM t r a = PrattM | |
{ runPrattM :: ReaderT (Tables t r) (StateT [t] (ExceptionT String Id)) a |
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 ParallelListComp #-} | |
import Data.Char (isDigit) | |
import Data.List (nub) | |
import Data.Monoid ((<>)) | |
parse :: Eq a => Parser tk a -> [tk] -> Maybe [a] | |
parse p tk = case runParser p tk of | |
[] -> Nothing | |
xs -> Just $ nub $ map snd xs |
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
" Vim syntax file | |
" Language: GIDL | |
" Last Change: 2014 April 17 | |
" Maintainer: Getty Ritter <[email protected]> | |
if version < 600 | |
syntax clear | |
elseif exists("b:current_syntax") | |
finish | |
endif |
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
;; a simple major mode for editing GIDL files. | |
(setq gidl-font-lock | |
'(( "def-\\(enum\\|struct\\|newtype\\|interface\\)" | |
. font-lock-keyword-face ) | |
( "def-\\(enum\\|struct\\|newtype\\|interface\\) (?\\([A-Za-z0-9_-]*\\)" | |
2 font-lock-function-name-face ) | |
( "[us]int\\(8\\|16\\|32\\|64\\)_t\\|bool_t\\|float_t\\|double_t" | |
. font-lock-builtin-face))) |
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
#!/bin/bash -e | |
# ghc wrapper script (for managing installed GHC versions) | |
# this is a small script I use that allows multiple simultaneous ghc | |
# installations. This makes the following assumptions about how | |
# you want to set up your system: | |
# - GHC version {X} is installed with prefix ~/install/ghc-${X} | |
# - A file naming the current selected GHC version is placed | |
# at ~/.current-ghc | |
# - cabal is configured to point to this script instead of ghc |
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
#![feature(unboxed_closures)] | |
#![feature(core)] | |
#![feature(io)] | |
use std::old_io::stdio::{stdin}; | |
use std::collections::HashMap; | |
// This is our toy state example. | |
#[derive(Debug)] | |
struct State { |
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
#!/bin/sh | |
# This is a wrapper around cabal which will fail to execute if | |
# it's not invoked in a sandbox, although this behaviour can be | |
# worked around (with a warning message) using the command-line | |
# flag `--trust-me`. | |
contains_escape() { | |
# Find out whether the arguments contain --trust-me | |
ARR=$@ |
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
use std::io::File; | |
use std::io::stdio::{stdin,print}; | |
use std::iter::range; | |
use std::os; | |
use std::rand::{Rng,task_rng}; | |
use std::vec::as_vec; | |
/* This program will take a file that describes a 'mad libs template' as | |
* argument and ask the user for the correct parts of speech in a random | |
* order, and then stitch the resulting mad lib together. This was a very |
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 Data.Aeson (decode, FromJSON) | |
import Data.ByteString.Lazy (ByteString) | |
import Data.Monoid (First(..), (<>)) | |
decodeOneOf :: (FromJSON x, FromJSON y) => ByteString -> Maybe (Either x y) | |
decodeOneOf bs = getFirst (First (fmap Left (decode bs)) <> First (fmap Right (decode bs))) | |
-- or more straightforwardly | |
decodeOneOf' :: (FromJSON x, FromJSON y) => ByteString -> Maybe (Either x y) |
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 Main where | |
import NiceMain | |
main = nicemain go where go x y z = print $ (x && y) || z |