Skip to content

Instantly share code, notes, and snippets.

What

A technique for writing parsers.

Why

  • Easy to understand
  • Generally applicable
  • Full power of the programming language at your disposal
  • Declarative
~/Projects/mrcss
( master )☛ time npm test
> mrcss@1.0.0 test /Users/michaeltbaker/Projects/mrcss
> mocha --compilers js:babel-core/register test/*
Hello test
1) does a thing
@MichaelBaker
MichaelBaker / gist:5810053
Last active December 18, 2015 16:18
Breadth first numbering
data Tree a = EndNode | Leaf | Node a (Tree a) (Tree a)
data FlatTree = FlatLeaf | FlatNode deriving (Show)
data NumberedTree a = NumLeaf | NumNode Integer deriving (Show)
instance (Show a) => Show (Tree a) where
show = showTreeIndented 0
where showTreeIndented indentation Leaf = concat (take indentation $ repeat " ") ++ "[]\n"
showTreeIndented indentation (Node value left right) = concat (take indentation $ repeat " ") ++ (show value) ++ "\n" ++ showTreeIndented (indentation + 1) left ++ showTreeIndented (indentation + 1) right
import Graphics.UI.Gtk
import Graphics.Rendering.Cairo
main :: IO ()
main = do
initGUI
window <- windowNew
set window [windowTitle := "Hello Cairo 4",
windowDefaultWidth := 300, windowDefaultHeight := 200,
containerBorderWidth := 15 ]
{error,
{error,function_clause,
[{rabbit_mgmt_wm_exchange_publish,bad,
[{function_clause,
[{rabbit_exchange_type_lvc,route,
[{exchange,
{resource,<<"/">>,exchange,<<"cached_real_time_traffic_updates">>},
'x-lvc',true,false,false,[],undefined},
{delivery,true,false,<0.1091.0>,
{basic_message,
warning: there are multiple derivations named ‘nodejs-0.12.0’; using the first one
installing ‘nodejs-0.12.0’
these derivations will be built:
/nix/store/8ap1vgh9979cl8p4b3c4xl3r8nqs1iid-nodejs-0.12.0.drv
building path(s) ‘/nix/store/pv1l6a2dqwfy41ldnpvgp1i7arzfvkqr-nodejs-0.12.0’
unpacking sources
unpacking source archive /nix/store/846c6d0zaqpg50ph7h6vba3fgdprcmqj-node-v0.12.0.tar.gz
source root is node-v0.12.0
patching sources
applying patch /nix/store/w9f0cqmzjgpdcyfqaihzf80bdwn7x4xg-no-xcode.patch
26 client.authorization = Signet::OAuth2::Client.new(
27 :token_credential_uri => 'https://www.googleapis.com/oauth2/v3/token',
28 :audience => 'https://www.googleapis.com/oauth2/v3/token',
29 :scope => scope,
30 :issuer => GMAIL_ISSUER,
31 :signing_key => key,
32 :person => employee_email_address,
33 )
/*
data Creator = Stylist Int
| Member Int
| Service
data Service = Service1
| Service2
*/
select * from outfits where creator = (Stylist _);
{-# LANGUAGE NoMonomorphismRestriction #-}
class Symantics r where
int :: Int -> r Int
bool :: Bool -> r Bool
add :: r Int -> r Int -> r Int
mul :: r Int -> r Int -> r Int
leq :: r Int -> r Int -> r Bool
if_ :: r Bool -> r a -> r a -> r a
app :: r (a -> b) -> r a -> r b

I'm experimenting with some ideas and I think one of the problems I have could be solved with lenses, but it doesn't seem to work how I expect it to when I try to implement it.

I want to create a tree of data structures, where each node stores a lens that goes from the root of the tree down to that node. Here is a conceptual image. The idea in that image is that the color of the lens matches the color of the path that it represents through the tree.

Here is an example of a tree shaped data structure without storing the path lenses at the nodes:

{-# LANGUAGE TemplateHaskell #-}