Skip to content

Instantly share code, notes, and snippets.

View startling's full-sized avatar

Lizzie Dixon startling

View GitHub Profile
@startling
startling / gist:6152089
Created August 4, 2013 21:48
coatl test suite
Ok, modules loaded: Main, Language.Coatl.Abstract, Language.Coatl.Parser.Expression, Language.Coatl.Parser.Declaration, Language.Coatl.Graph, Language.Coatl.Check, Language.Coatl.Check.Types.
*Main> main
Language.Coatl.Parser.Expression
expression
- parses names
- parses operators
- parses infix operators
- parses lambdas
- parses the type of the identity function
@startling
startling / Graph.hs
Last active December 20, 2015 07:39
-- | Some functions on directed graphs.
module Language.Coatl.Graph where
-- base
import Data.Maybe
-- containers
import Data.Map (Map)
import qualified Data.Map as M
import Data.Set (Set)
import qualified Data.Set as S
-- mtl
@startling
startling / small.coatl
Last active December 19, 2015 09:28
Right (Module {_module' = Just (ModuleName ["small-example"]), _modDoc = Just "A small example module!", _imports = [ModuleName ["internal"]], _modPragma = [NoPrelude], _declarations = [Declaration {_named = "id", _declared = Lambda (Lambda (Reference Nothing)), _annotation = Annotation {_type' = Just (Call (Call (Reference (Just (ModuleName ["i…
[ import = [ internal ]
, module = small-example
, pragma = no-prelude
, doc = "A small example module!"
]
id _ x = x
[ doc = "The identity function"
, type = dependent type (\a -> function a a)
]
module Control.Applicative.Recipes where
-- base
import Control.Applicative
import Data.Foldable
import Data.Traversable
import Data.Monoid
-- containers
import Data.Set
data Recipe k v m a = Recipe
def bit_iter(bits, n):
"Iterate over the bits of an integer, padding it to `n` digits."
return ((bits >> i) & 1 for i in xrange(n - 1, -1, -1))
def unsigned_bin(x, n=32):
"Print the unsigned binary representation of an integer."
return "".join(repr(y) for y in bit_iter(x, n))
print unsigned_bin(0b101, 8) # '00000101'
import Sheets
import Control.Applicative
import Control.Monad.State
import Data.Text (Text)
import qualified Data.Text as T
import qualified Data.Text.IO as T
simple :: [T.Text] -> Table (State Int) Text
simple = Table [counter id, see]
data MaybeT : (Type -> Type) -> Type where
MT : {m : Type -> Type} -> m (Maybe a) -> MaybeT m a
@startling
startling / multidecorator.py
Last active December 14, 2015 20:08
Multiple-argument decorators in python via classes!
def multidecorator(fn):
class _MultiDecorator(object):
class __metaclass__(type):
def __new__(cls, name, bases, dict):
# No magic on the first class with this metaclass
if bases == (object,):
return type.__new__(cls, fn.__name__, bases, dict)
else:
return fn(**dict)
return _MultiDecorator
\begin{diagram}
\named{a} \box \box \\
\box \box \named{b} \\
\box \box \empty
\end{diagram}
@startling
startling / gist:4349917
Last active December 10, 2015 00:18
`idris --log 3 heterogenous.idr`
Elaborating {__Infer0}
builtin:0
---> Type a
builtin:0:Constructor {__infer0} : {{A0} : Type} -> ({a0} : {A0}) -> {__Infer0}
Rechecking ({A0} : Type 0) -> {A0} -> {__Infer0}
---> {__infer0} : ({A0} : Type c) -> {A0} -> {__Infer0}
Forced: {__infer0} []
from ({A0} : Type c) -> {A0} -> {__Infer0}
Elaborating {__Unit0}
builtin:0