Skip to content

Instantly share code, notes, and snippets.

-- Copyright 2018 Google LLC.
-- SPDX-License-Identifier: Apache-2.0
{-# LANGUAGE FlexibleContexts #-}
import Control.Applicative
import Control.Monad.Writer
data Expr = Lit Int | Plus Expr Expr | Times Expr Expr
deriving (Eq, Show)
@polux
polux / designer.html
Created June 27, 2014 12:47
designer
<link rel="import" href="../paper-input/paper-input.html">
<polymer-element name="my-element">
<template>
<style>
:host {
position: absolute;
width: 100%;
height: 100%;
@polux
polux / gist:8375474
Created January 11, 2014 19:19
Staged Interpreter
class None {
None();
}
class Some {
final value;
Some(this.value);
}
/* environments */
@polux
polux / gist:8030692
Created December 18, 2013 22:08
Staged contains method for binary trees
class Node {
final val;
final left;
final right;
Node(this.val, this.left, this.right);
insert(n) =>
n.lt(this.val)
? new Node(this.val, this.left.insert(n), this.right)
@polux
polux / gist:8021388
Created December 18, 2013 12:22
Staged "contains" method
class Cons {
final x;
final xs;
Cons(this.x, this.xs);
freeze() => new Cons(((v) => <v>)(this.x), this.xs.freeze());
contains(e) => < (~this.x).eq(~e) ? true : ~(this.xs.contains(e)) >;
}
@polux
polux / gist:3779102
Created September 24, 2012 23:31
JJ's problem
import Data.Char
main = interact unindent
unindent = unlines . unindentLines . lines
unindentLines ls = map (drop commonPrefixLength) ls
where -- the number of characters to drop from each line
commonPrefixLength = length (commonPrefix prefixes)
-- whitespace-only prefixes of non-empty lines of ls
<!DOCTYPE HTML>
<html>
<head>
<script type="text/javascript" src="flapjax.js"></script>
<script>
function onload() {
/****** utils ******/
// 2d vectors