<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>weaselhat</title>
	<atom:link href="http://www.weaselhat.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.weaselhat.com</link>
	<description></description>
	<lastBuildDate>Wed, 01 Feb 2012 20:18:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>QuickRedex</title>
		<link>http://www.weaselhat.com/2012/02/01/quickredex/</link>
		<comments>http://www.weaselhat.com/2012/02/01/quickredex/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 20:18:01 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=321</guid>
		<description><![CDATA[Following Robby Findler&#8217;s excellent presentation on PLT Redex at POPL (check out the paper and presentation!), I hacked up something similar in Haskell. Naturally, it&#8217;s all manual, and there&#8217;s none of the publication or visualization support, but the essence is there. Here&#8217;s the code for the untyped lambda calculus: Haskell [Show Styled Code]: module Untyped [...]]]></description>
			<content:encoded><![CDATA[<p>Following <a href="http://eecs.northwestern.edu/~robby/" title="I am the walrus.">Robby Findler&#8217;s</a> excellent presentation on <a href="http://redex.plt-scheme.org/">PLT Redex</a> at POPL (check out the <a href="http://eecs.northwestern.edu/~robby/lightweight-metatheory/">paper and presentation!</a>), I hacked up something similar in Haskell.  Naturally, it&#8217;s all manual, and there&#8217;s none of the publication or visualization support, but the essence is there.  Here&#8217;s the code for the untyped lambda calculus:</p>
<div class="synthi_code" style="display:none;" id ="plain_synthi_4f2d16603a7e8">
<div class="synthi_header" style="font-weight:bold;"> Haskell <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('styled_synthi_4f2d16603a7e8').style.display='block';document.getElementById('plain_synthi_4f2d16603a7e8').style.display='none';return false">Show Styled Code</a>]:</span></div>
<pre style="width:100%;overflow:auto;">
module Untyped where

import Control.Monad
import Data.Maybe
import Test.QuickCheck

data Expr =
    Var Int
  | Lambda Expr
  | App Expr Expr

showExpr :: Int -> Expr -> String
showExpr _b (Var n) = &#034;var&#034; ++ show n
showExpr b (Lambda e) = &#034;lambda. &#034; ++ showExpr (b+1) e
showExpr b (App e1 e2) = &#034;(&#034; ++ showExpr b e1 ++ &#034; &#034; ++ showExpr b e2 ++ &#034;)&#034;

instance Show Expr where
  show e = showExpr 0 e

size :: Expr -> Int
size (Var _) = 1
size (Lambda e) = 1 + size e
size (App e1 e2) = size e1 + size e2

wellLexed :: Expr -> Bool
wellLexed = wellLexedAux 0
  where wellLexedAux :: Int -> Expr -> Bool
        wellLexedAux b (Var n) = 0 <= n &#038;&#038; n < b
        wellLexedAux b (Lambda e) = wellLexedAux (b+1) e
        wellLexedAux b (App e1 e2) = wellLexedAux b e1 &#038;&#038; wellLexedAux b e2

arbitraryExpr :: Int -> Int -> Gen Expr
arbitraryExpr n 0 = oneof [return $ Lambda $ Var 0] -- base case
arbitraryExpr n max = do
  oneof $
    (if n < max
     then [arbitraryExpr (n+1) (max-1) >>= return . Lambda]
     else []) ++
    (if n > 0
     then [choose (0,n-1) >>= return . Var]
     else []) ++
    [do { e1 <- arbitraryExpr n (max `div` 2);
          e2 <- arbitraryExpr n (max `div` 2);
          return $ App e1 e2 }]

instance Arbitrary Expr where
  arbitrary = sized $ \max -> arbitraryExpr 0 max

-- All the terms we generate should be well-lexed
prop_WellLexed e = collect (size e) $ wellLexed e

subst :: Expr -> Int -> Expr -> Expr
subst e n (Var n')
  | n == n' = e
  | otherwise = (Var n')
subst e n (Lambda e') = Lambda $ subst e (n+1) e'
subst e n (App e1 e2) = App (subst e n e1) (subst e n e2)

shift :: Int -> Expr -> Expr
shift i (Var n) = if n < i then Var n else Var (n-1)
shift i (Lambda e) = Lambda $ shift (i+1) e
shift i (App e1 e2) = App (shift i e1) (shift i e2)

value :: Expr -> Bool
value (Lambda e) = True
value _ = False

-- we can run this with m = Maybe or m = List
step :: MonadPlus m => Expr -> m Expr
step (Var _) = mzero -- unbound variable
step (Lambda e) = mzero -- found a term
step (App e1@(Lambda e11) e2)
  | value e2 = return $ shift 0 $ subst e2 0 e11
  | otherwise = do
    e2' <- step e2
    return $ App e1 e2'
step (App e1 e2) = do
  e1' <- step e1
  return $ App e1' e2

-- if we can step, we'd better preserve scope
prop_StepWellLexed e = isJust next ==> wellLexed (fromJust next)
  where next = step e

-- verify progress
prop_Progress e = (classify isValue &#034;value&#034;) $ (classify (not isValue) &#034;step&#034;) $ value e || isJust (step e)
  where isValue = value e

-- use the List monad to ensure determinacy
prop_Deterministic e = nextStates > 0 ==> nextStates == 1
  where nextStates = length $ step e
</pre>
</div>
<div class="synthi_code" style="display:block;" id ="styled_synthi_4f2d16603a7e8">
<div class="synthi_header" style="font-weight:bold;"> Haskell <span  class="synthi_button"style="font-weight:lighter;font-size:smaller;">[<a href="#" onClick="javascript:document.getElementById('plain_synthi_4f2d16603a7e8').style.display='block';document.getElementById('styled_synthi_4f2d16603a7e8').style.display='none';return false">Show Plain Code</a>]:</span></div>
<div class="haskell" style="font-family: monospace;">
<ol>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">module</span> Untyped <span style="color: #06c; font-weight: bold;">where</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">import</span> Control.<span style="color: #060;">Monad</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">import</span> <span style="color: #06c; font-weight: bold;">Data</span>.<span style="color: #060;">Maybe</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">import</span> Test.<span style="color: #060;">QuickCheck</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">data</span> Expr =</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; Var Int</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | Lambda Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | App Expr Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">showExpr :: Int -&gt; Expr -&gt; String</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">showExpr _b <span style="color: #6c6;">&#40;</span>Var n<span style="color: #6c6;">&#41;</span> = <span style="color: #3cb371;">&quot;var&quot;</span> ++ show n</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">showExpr b <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = <span style="color: #3cb371;">&quot;lambda. &quot;</span> ++ showExpr <span style="color: #6c6;">&#40;</span>b<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span> e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">showExpr b <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = <span style="color: #3cb371;">&quot;(&quot;</span> ++ showExpr b e1 ++ <span style="color: #3cb371;">&quot; &quot;</span> ++ showExpr b e2 ++ <span style="color: #3cb371;">&quot;)&quot;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">instance</span> Show Expr <span style="color: #06c; font-weight: bold;">where</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; show e = showExpr <span style="color: #c6c;">0</span> e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">size :: Expr -&gt; Int</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">size <span style="color: #6c6;">&#40;</span>Var _<span style="color: #6c6;">&#41;</span> = <span style="color: #c6c;">1</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">size <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = <span style="color: #c6c;">1</span> + size e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">size <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = size e1 + size e2</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">wellLexed :: Expr -&gt; Bool</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">wellLexed = wellLexedAux <span style="color: #c6c;">0</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #06c; font-weight: bold;">where</span> wellLexedAux :: Int -&gt; Expr -&gt; Bool</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; wellLexedAux b <span style="color: #6c6;">&#40;</span>Var n<span style="color: #6c6;">&#41;</span> = <span style="color: #c6c;">0</span> &lt;= n &amp;&amp; n &lt; b</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; wellLexedAux b <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = wellLexedAux <span style="color: #6c6;">&#40;</span>b<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span> e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; wellLexedAux b <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = wellLexedAux b e1 &amp;&amp; wellLexedAux b e2</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">arbitraryExpr :: Int -&gt; Int -&gt; Gen Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">arbitraryExpr n <span style="color: #c6c;">0</span> = oneof <span style="color: #6c6;">&#91;</span><span style="color: #06c; font-weight: bold;">return</span> $ Lambda $ Var <span style="color: #c6c;">0</span><span style="color: #6c6;">&#93;</span> <span style="">&#8211; base case</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">arbitraryExpr n max = <span style="color: #06c; font-weight: bold;">do</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; oneof $ </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">if</span> n &lt; max </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">then</span> <span style="color: #6c6;">&#91;</span>arbitraryExpr <span style="color: #6c6;">&#40;</span>n<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>max<span style="color: #c6c;">-1</span><span style="color: #6c6;">&#41;</span> &gt;&gt;= <span style="color: #06c; font-weight: bold;">return</span> . <span style="color: #060;">Lambda</span><span style="color: #6c6;">&#93;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">else</span> <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span><span style="color: #6c6;">&#41;</span> ++ </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">if</span> n &gt; <span style="color: #c6c;">0</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">then</span> <span style="color: #6c6;">&#91;</span>choose <span style="color: #6c6;">&#40;</span><span style="color: #c6c;">0</span>,n<span style="color: #c6c;">-1</span><span style="color: #6c6;">&#41;</span> &gt;&gt;= <span style="color: #06c; font-weight: bold;">return</span> . <span style="color: #060;">Var</span><span style="color: #6c6;">&#93;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp;<span style="color: #06c; font-weight: bold;">else</span> <span style="color: #6c6;">&#91;</span><span style="color: #6c6;">&#93;</span><span style="color: #6c6;">&#41;</span> ++</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #6c6;">&#91;</span><span style="color: #06c; font-weight: bold;">do</span> <span style="color: #6c6;">&#123;</span> e1 &lt;- arbitraryExpr n <span style="color: #6c6;">&#40;</span>max `div` <span style="color: #c6c;">2</span><span style="color: #6c6;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; e2 &lt;- arbitraryExpr n <span style="color: #6c6;">&#40;</span>max `div` <span style="color: #c6c;">2</span><span style="color: #6c6;">&#41;</span>;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">return</span> $ App e1 e2 <span style="color: #6c6;">&#125;</span><span style="color: #6c6;">&#93;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #06c; font-weight: bold;">instance</span> Arbitrary Expr <span style="color: #06c; font-weight: bold;">where</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; arbitrary = sized $ \max -&gt; arbitraryExpr <span style="color: #c6c;">0</span> max</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">&#8211; All the terms we generate should be well-lexed</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">prop_WellLexed e = collect <span style="color: #6c6;">&#40;</span>size e<span style="color: #6c6;">&#41;</span> $ wellLexed e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">subst :: Expr -&gt; Int -&gt; Expr -&gt; Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">subst e n <span style="color: #6c6;">&#40;</span>Var n&#8217;<span style="color: #6c6;">&#41;</span> </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | n == n&#8217; = e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | <span style="color: #06c; font-weight: bold;">otherwise</span> = <span style="color: #6c6;">&#40;</span>Var n&#8217;<span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">subst e n <span style="color: #6c6;">&#40;</span>Lambda e&#8217;<span style="color: #6c6;">&#41;</span> = Lambda $ subst e <span style="color: #6c6;">&#40;</span>n<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span> e&#8217;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">subst e n <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = App <span style="color: #6c6;">&#40;</span>subst e n e1<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>subst e n e2<span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">shift :: Int -&gt; Expr -&gt; Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">shift i <span style="color: #6c6;">&#40;</span>Var n<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">if</span> n &lt; i <span style="color: #06c; font-weight: bold;">then</span> Var n <span style="color: #06c; font-weight: bold;">else</span> Var <span style="color: #6c6;">&#40;</span>n<span style="color: #c6c;">-1</span><span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">shift i <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = Lambda $ shift <span style="color: #6c6;">&#40;</span>i<span style="color: #c6c;">+1</span><span style="color: #6c6;">&#41;</span> e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">shift i <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = App <span style="color: #6c6;">&#40;</span>shift i e1<span style="color: #6c6;">&#41;</span> <span style="color: #6c6;">&#40;</span>shift i e2<span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">value :: Expr -&gt; Bool</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">value <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">True</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">value _ = <span style="color: #06c; font-weight: bold;">False</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">&#8211; we can run this with m = Maybe or m = List</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">step :: MonadPlus m =&gt; Expr -&gt; m Expr</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">step <span style="color: #6c6;">&#40;</span>Var _<span style="color: #6c6;">&#41;</span> = mzero <span style="">&#8211; unbound variable</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">step <span style="color: #6c6;">&#40;</span>Lambda e<span style="color: #6c6;">&#41;</span> = mzero <span style="">&#8211; found a term</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">step <span style="color: #6c6;">&#40;</span>App e1@<span style="color: #6c6;">&#40;</span>Lambda e11<span style="color: #6c6;">&#41;</span> e2<span style="color: #6c6;">&#41;</span> </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | value e2 = <span style="color: #06c; font-weight: bold;">return</span> $ shift <span style="color: #c6c;">0</span> $ subst e2 <span style="color: #c6c;">0</span> e11</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; | <span style="color: #06c; font-weight: bold;">otherwise</span> = <span style="color: #06c; font-weight: bold;">do</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; e2&#8242; &lt;- step e2</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">return</span> $ App e1 e2&#8242;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">step <span style="color: #6c6;">&#40;</span>App e1 e2<span style="color: #6c6;">&#41;</span> = <span style="color: #06c; font-weight: bold;">do</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; e1&#8242; &lt;- step e1</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #06c; font-weight: bold;">return</span> $ App e1&#8242; e2</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">&#8211; if we can step, we&#8217;d better preserve scope</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">prop_StepWellLexed e = isJust next ==&gt; wellLexed <span style="color: #6c6;">&#40;</span>fromJust next<span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #06c; font-weight: bold;">where</span> next = step e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; &nbsp; &nbsp; &nbsp; </div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">&#8211; verify progress</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">prop_Progress e = <span style="color: #6c6;">&#40;</span>classify isValue <span style="color: #3cb371;">&quot;value&quot;</span><span style="color: #6c6;">&#41;</span> $ <span style="color: #6c6;">&#40;</span>classify <span style="color: #6c6;">&#40;</span><span style="color: #06c; font-weight: bold;">not</span> isValue<span style="color: #6c6;">&#41;</span> <span style="color: #3cb371;">&quot;step&quot;</span><span style="color: #6c6;">&#41;</span> $ value e || isJust <span style="color: #6c6;">&#40;</span>step e<span style="color: #6c6;">&#41;</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #06c; font-weight: bold;">where</span> isValue = value e</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp;</div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="">&#8211; use the List monad to ensure determinacy</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">prop_Deterministic e = nextStates &gt; <span style="color: #c6c;">0</span> ==&gt; nextStates == <span style="color: #c6c;">1</span></div>
</li>
<li style="font-weight: bold;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">&nbsp; <span style="color: #06c; font-weight: bold;">where</span> nextStates = length $ step e </div>
</li>
</ol>
</div>
</div>
<p>One of the trickiest things here was making sure I was generating well lexed lambda terms that were small enough to be tractable.  It would have been even harder, I think, with a more explicit representation of variables or binding.  Thoughts, variations?  Or, perhaps, complaints that I should have done this with GADTS or in Coq?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2012/02/01/quickredex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>@mgrnbrg on twitter</title>
		<link>http://www.weaselhat.com/2012/02/01/mgrnbrg-on-twitter/</link>
		<comments>http://www.weaselhat.com/2012/02/01/mgrnbrg-on-twitter/#comments</comments>
		<pubDate>Wed, 01 Feb 2012 16:07:58 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=318</guid>
		<description><![CDATA[Just a note: I&#8217;ve had a (mostly idle) Twitter account for a while, @mgrnbrg. Feel free to say hello!]]></description>
			<content:encoded><![CDATA[<p>Just a note: I&#8217;ve had a (mostly idle) Twitter account for a while, <a href="https://twitter.com/#!/mgrnbrg">@mgrnbrg</a>.  Feel free to say hello!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2012/02/01/mgrnbrg-on-twitter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Towards a core calculus for implicitly migration-capable applications</title>
		<link>http://www.weaselhat.com/2011/10/25/migration/</link>
		<comments>http://www.weaselhat.com/2011/10/25/migration/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 16:38:31 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Submissions]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=291</guid>
		<description><![CDATA[Yitzhak Mandelbaum and I have been thinking about language support for program migration. We submitted a short paper, Towards a core calculus for implicitly migration-capable applications, to PEPM&#8217;12 summarizing what we&#8217;ve done so far and the direction we&#8217;re headed. Here&#8217;s the abstract: Mobile computational devices, like smartphones, tablets and laptops, have become a standard part [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www2.research.att.com/~yitzhak/">Yitzhak Mandelbaum</a> and I have been thinking about language support for program migration.  We submitted a short paper, <a class="paper" href="http://www.cis.upenn.edu/~mgree/papers/pepm2012_submission.pdf">Towards a core calculus for implicitly migration-capable applications</a>, to <a href="http://www.program-transformation.org/PEPM12">PEPM&#8217;12</a> summarizing what we&#8217;ve done so far and the direction we&#8217;re headed.  Here&#8217;s the abstract:</p>
<blockquote><p>
Mobile computational devices, like smartphones, tablets and laptops, have become a standard part of the computing landscape. Moreover, many users regularly interact with an assortment of devices, including mobile ones. Therefore, the ability to migrate UI-enabled applications is becoming increasingly important. We describe a design-pattern for applications to simplify support for user-session migration and provide an overview of a lambda calculus for which significant elements of the design pattern can be implemented automatically.
</p></blockquote>
<p>We&#8217;d appreciate any ideas, comments, or questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/10/25/migration/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPEnkoder 1.11</title>
		<link>http://www.weaselhat.com/2011/10/11/phpenkoder-1-11/</link>
		<comments>http://www.weaselhat.com/2011/10/11/phpenkoder-1-11/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 13:47:02 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=288</guid>
		<description><![CDATA[A change not due to NilsOla Nilsson broke PHPEnkoder 1.10 on mailto: links. But he caught this almost immediately and sent me a fix. PHPEnkoder 1.11 should work fine. Thanks, NilsOla! As usual, updates are available from the WordPress plugin directory or from your dashboard.]]></description>
			<content:encoded><![CDATA[<p>A change not due to <a href="http://www.femtrappor.se">NilsOla Nilsson</a> broke PHPEnkoder 1.10 on <tt>mailto:</tt> links.  But he caught this almost immediately and sent me a fix.  PHPEnkoder 1.11 should work fine.  Thanks, NilsOla!</p>
<p>As usual, updates are available from the <a href="http://wordpress.org/extend/plugins/php-enkoder/">WordPress plugin directory</a> or from your dashboard.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/10/11/phpenkoder-1-11/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHPEnkoder 1.10</title>
		<link>http://www.weaselhat.com/2011/10/05/phpenkoder-1-10/</link>
		<comments>http://www.weaselhat.com/2011/10/05/phpenkoder-1-10/#comments</comments>
		<pubDate>Wed, 05 Oct 2011 15:48:48 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=281</guid>
		<description><![CDATA[NilsOla Nilsson pointed out a few changes I could make to the link-detection regexes that resolved a few issues with overzealous encoding. As usual, updates are available from the WordPress plugin directory&#8212;or, of course, automatically in your dashboard.]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.femtrappor.se">NilsOla Nilsson</a> pointed out a few changes I could make to the link-detection regexes that resolved a few issues with overzealous encoding.</p>
<p>As usual, updates are available from the <a href="http://wordpress.org/extend/plugins/php-enkoder/">WordPress plugin directory</a>&#8212;or, of course, automatically in your dashboard.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/10/05/phpenkoder-1-10/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPEnkoder 1.9</title>
		<link>http://www.weaselhat.com/2011/03/15/phpenkoder-1-9/</link>
		<comments>http://www.weaselhat.com/2011/03/15/phpenkoder-1-9/#comments</comments>
		<pubDate>Tue, 15 Mar 2011 20:16:49 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=263</guid>
		<description><![CDATA[Per a bug report from Kim Carr at WebShoppingSystems.com, PHPEnkoder now correctly supports whitespace&#8212;this bug was most noticeable in email hidden; JavaScript is required shortcodes. Updates are available from the WordPress plugin directory&#8212;or straight from your dashboard. (We&#8217;ve come quite a way from 2.3, haven&#8217;t we!)]]></description>
			<content:encoded><![CDATA[<p>Per a bug report from <a href="http://webshoppingsystems.com">Kim Carr at WebShoppingSystems.com</a>, PHPEnkoder now correctly supports whitespace&#8212;this bug was most noticeable in <tt>[enkode]</tt> shortcodes.</p>
<p>Updates are available from the <a href="http://wordpress.org/extend/plugins/php-enkoder/">WordPress plugin directory</a>&#8212;or straight from your dashboard.  (We&#8217;ve come quite a way from 2.3, haven&#8217;t we!)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/03/15/phpenkoder-1-9/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHPEnkoder 1.8</title>
		<link>http://www.weaselhat.com/2011/02/21/phpenkoder-1-8/</link>
		<comments>http://www.weaselhat.com/2011/02/21/phpenkoder-1-8/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 02:05:18 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=253</guid>
		<description><![CDATA[Per Tom&#8217;s report, version 1.8 fixes a few minor bugs. If PHPEnkoder is working for you, there&#8217;s no pressing need to upgrade. Updates from now on will only be available from the WordPress plugin directory.]]></description>
			<content:encoded><![CDATA[<p>Per <a href="http://wordpress.org/support/topic/phpenkoder-errors-with-debugging-on#post-1952375">Tom&#8217;s report</a>, version 1.8 fixes a few minor bugs.  If PHPEnkoder is working for you, there&#8217;s no pressing need to upgrade.</p>
<p>Updates from now on will only be available from <a href="http://wordpress.org/extend/plugins/php-enkoder/">the WordPress plugin directory</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/02/21/phpenkoder-1-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Lovelace and Babbage vs. The Organist</title>
		<link>http://www.weaselhat.com/2011/01/19/lovelace-and-babbage-vs-the-organist/</link>
		<comments>http://www.weaselhat.com/2011/01/19/lovelace-and-babbage-vs-the-organist/#comments</comments>
		<pubDate>Wed, 19 Jan 2011 19:33:35 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=245</guid>
		<description><![CDATA[The latest and longest-yet episode of the graphic novel Lovelace and Babbage&#8212;Lovelace and Babbage vs. the Organist&#8212;at 2D Goggles has come to a close. If you haven&#8217;t seen it before, check it out! I highly recommend it.]]></description>
			<content:encoded><![CDATA[<p>The latest and longest-yet episode of the graphic novel Lovelace and Babbage&#8212;Lovelace and Babbage vs. the Organist&#8212;at <a href="http://2dgoggles.com/">2D Goggles</a> has come to a close.  If you haven&#8217;t seen it before, check it out!  I highly recommend it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/01/19/lovelace-and-babbage-vs-the-organist/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ESOP 2011 Papers</title>
		<link>http://www.weaselhat.com/2011/01/04/esop-2011-papers/</link>
		<comments>http://www.weaselhat.com/2011/01/04/esop-2011-papers/#comments</comments>
		<pubDate>Tue, 04 Jan 2011 15:30:01 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Papers]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=237</guid>
		<description><![CDATA[I&#8217;m happy to announce the final versions of two ESOP 2011 papers. Polymorphic Contracts was work done with Jo&#227;o Belo, Atsushi Igarashi, and my advisor, Benjamin Pierce. Measure Transformer Semantics for Bayesian Machine Learning was work done at my internship at MSR Cambridge this summer; the real heroes of this story are Johannes Borgstr&#246;m, Andy [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m happy to announce the final versions of two ESOP 2011 papers.  <a class="paper" href="http://www.cis.upenn.edu/~mgree/papers/esop2011_fh.pdf">Polymorphic Contracts</a> was work done with <a href="http://pwp.net.ipl.pt/cc.isel/jbelo/">Jo&atilde;o Belo</a>, <a href="http://www.sato.kuis.kyoto-u.ac.jp/~igarashi/index.html.en">Atsushi Igarashi</a>, and my advisor, <a href="http://www.cis.upenn.edu/~bcpierce/">Benjamin Pierce</a>.  <a class="paper" href="http://www.cis.upenn.edu/~mgree/papers/esop2011_mts.pdf">Measure Transformer Semantics for Bayesian Machine Learning</a> was work done at my internship at MSR Cambridge this summer; the real heroes of this story are Johannes Borgstr&ouml;m, <a href="http://research.microsoft.com/en-us/um/people/adg/">Andy Gordon</a>, James Margetson, and <a href="http://research.microsoft.com/en-us/people/jvangael/">Jurgen Van Gael</a>.</p>
<p>See you in Saarbr&uuml;cken?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2011/01/04/esop-2011-papers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Polymorphic Contracts</title>
		<link>http://www.weaselhat.com/2010/10/27/polymorphic-contracts/</link>
		<comments>http://www.weaselhat.com/2010/10/27/polymorphic-contracts/#comments</comments>
		<pubDate>Wed, 27 Oct 2010 15:27:00 +0000</pubDate>
		<dc:creator>Michael Greenberg</dc:creator>
				<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Submissions]]></category>

		<guid isPermaLink="false">http://www.weaselhat.com/?p=226</guid>
		<description><![CDATA[Jo&#227;o Belo, Atsushi Igarashi, Benjamin Pierce, and I submitted a paper, Polymorphic Contracts, to ESOP&#8217;11. Here&#8217;s the abstract: Manifest contracts track precise properties by refining types with predicates&#8212;e.g., {x:Int &#124; x > 0} denotes the positive integers. Contracts and polymorphism make a natural combination: programmers can give abstract types strong contracts, precisely stating pre- and [...]]]></description>
			<content:encoded><![CDATA[<p>Jo&atilde;o Belo, <a href="http://www.sato.kuis.kyoto-u.ac.jp/~igarashi/index.html.en">Atsushi Igarashi</a>, <a href="http://www.cis.upenn.edu/~bcpierce/">Benjamin Pierce</a>, and I submitted a paper, <a class="paper" href="http://www.seas.upenn.edu/~mgree/papers/esop2011sub_fh.pdf">Polymorphic Contracts</a>, to <a href="http://software.imdea.org/~gbarthe/esop11/">ESOP&#8217;11</a>.  Here&#8217;s the abstract:</p>
<blockquote><p>
Manifest contracts track precise properties by refining types with predicates&mdash;e.g., <tt>{x:Int | x > 0}</tt> denotes the positive integers. Contracts and polymorphism make a natural combination: programmers can give abstract types strong contracts, precisely stating pre- and post-conditions while hiding implementation details&mdash;for example, an abstract type of stacks might specify that the pop operation has input type <tt>{x:&alpha; Stack | not (empty x)}</tt>. We formalize this combination by defining FH, a polymorphic calculus with manifest contracts, and establishing its fundamental properties, including type soundness and relational parametricity. Our development relies on a significant technical improvement over earlier presentations of contracts: instead of introducing a denotational model to break a problematic circularity between typing, subtyping, and evaluation, we develop the metatheory of contracts in a completely syntactic fashion, omitting subtyping from the core system and recovering it post facto as a derived property.
</p></blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.weaselhat.com/2010/10/27/polymorphic-contracts/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

