Permalink
Browse files

Merge branch 'master' of github.com:tomlokhorst/AwesomePrelude

  • Loading branch information...
2 parents 6035a55 + 3481d9c commit 20269dec02ca5cfcdf3eedae361fdcdbb4dc00bd @tomlokhorst committed Feb 6, 2010
Showing with 300 additions and 14 deletions.
  1. +73 −0 presentation/Conclusion.lhs
  2. +2 −1 presentation/Makefile
  3. +176 −0 presentation/Value.lhs
  4. +39 −11 presentation/code.fmt
  5. +10 −2 presentation/presentation.lhs
@@ -0,0 +1,73 @@
+%include polycode.fmt
+%include code.fmt
+
+%if style == newcode
+
+> {-# LANGUAGE GADTs #-}
+> {-# OPTIONS_GHC -F -pgmF lhs2tex -optF --pre #-}
+
+> module Conclusion where
+
+%endif
+
+% -----------------------------------------------------------------------------
+
+\begin{frame}
+\frametitle{This prototype}
+
+\begin{itemize}
+
+\item Abstract away from concrete datatypes.
+\item Abstract away from functions.
+\item Replace with type classes.\linebreak
+
+\item Different instances for different computational contexts.
+\item Functions look similar.
+\item Types get complicated.\linebreak
+
+\item Plain lazy and purely functional Haskell.
+\item Purely functional strict JavaScript.
+\item Functional reactive JavaScript.
+
+\end{itemize}
+
+\end{frame}
+
+% -----------------------------------------------------------------------------
+
+\begin{frame}
+\frametitle{Current problems}
+
+\begin{itemize}
+
+\item Explicit lifting of function application and recursion.
+\item Type signatures with big contexts.
+\item No sugar for pattern matching, let bindings, if-then-else.
+
+\end{itemize}
+
+\end{frame}
+
+% -----------------------------------------------------------------------------
+
+\begin{frame}
+\frametitle{Future work}
+
+\begin{itemize}
+
+\begin{item}
+ Additional computational contexts:
+ \begin{itemize}
+ \item Strict Haskell
+ \item Functional Reactive Haskell
+ \item Profiling support
+ \item C, Objective-C, C\tt{\#}, etc...
+ \end{itemize}
+\end{item}
+
+\item Syntactic front-end.
+
+\end{itemize}
+
+\end{frame}
+
@@ -1,4 +1,4 @@
-SRC = presentation.tex ArithExpr.tex Expr.tex BoolLike.tex RealExpr.tex
+SRC = presentation.tex ArithExpr.tex Expr.tex BoolLike.tex RealExpr.tex Value.tex Conclusion.tex code.fmt
.PHONY : clean $(SRC:%.tex=ghci-%)
@@ -7,6 +7,7 @@ ghci-% :
presentation.pdf : $(SRC)
latexmk -pdf -g $<
+ open presentation.pdf
%.tex : %.lhs
lhs2TeX -o $@ $<
View
@@ -0,0 +1,176 @@
+%include polycode.fmt
+%include code.fmt
+
+%if style == newcode
+
+> {-# LANGUAGE GADTs #-}
+> {-# OPTIONS_GHC -F -pgmF lhs2tex -optF --pre #-}
+
+> module Value where
+
+%endif
+
+% -----------------------------------------------------------------------------
+
+\begin{frame}
+
+> type Nm = String
+
+> data JavaScript a where
+> Con :: Nm -> JavaScript a
+> Prim :: ([Nm] -> Nm) -> [Nm] -> JavaScript a
+> App :: JavaScript (a -> b) -> JavaScript a -> JavaScript b
+> Lam :: (JavaScript a -> JavaScript b) -> JavaScript (a -> b)
+> Var :: Nm -> JavaScript a
+> Name :: Nm -> JavaScript a -> JavaScript a
+
+\end{frame}
+
+% -----------------------------------------------------------------------------
+
+\begin{frame}
+
+> instance FunC JavaScript where
+> lam f = Lam f
+> app f g = App f g
+
+> instance BoolC JavaScript where
+>
+> -- constructors:
+> true = Con "true"
+> false = Con "false"
+>
+> -- destructor:
+> bool x y z = fun3 "bool"
+> (\[e, t, b] -> concat [b,"?",t,"():",e,"()"])
+> (lam (const x)) (lam (const y)) z
+
+\end{frame}
+
+% -----------------------------------------------------------------------------
+
+\begin{frame}
+
+> instance ListC JavaScript where
+>
+> -- constructors:
+> nil = Con "{nil:1}"
+> cons = fun2 "cons"
+> (\[x, xs] -> concat ["{head:",x,",tail:",xs,"}"])
+>
+> -- destructor:
+> list b f = fun3 "list"
+> (\[n, c, xs] -> concat
+> [xs,".nil?",n,":",c,"(",xs,".head)(",xs,".tail)"]
+> ) b (lam2 f)
+
+\end{frame}
+
+% -----------------------------------------------------------------------------
+
+\begin{frame}
+
+> type a :-> b = Kleisli IO a b
+> type Code = String
+
+> compiler :: JavaScript a -> Code
+> compiler = runKleisli
+> $ ( Lambdas.instantiate :: JavaScript a :-> Expression )
+> . ( Defs.lift :: Expression :-> Definitions )
+> . ( Defs.eliminiateDoubles :: Definitions :-> Definitions )
+> . ( FreeVars.annotateDefs :: Definitions :-> DefinitionsFV )
+> . ( ClosedApplications.lift :: DefinitionsFV :-> Definitions )
+> . ( Parameters.reindex :: Definitions :-> Definitions )
+> . ( CommonDefs.eliminate :: Definitions :-> Definitions )
+> . ( Defs.dump :: Definitions :-> Code )
+
+\end{frame}
+
+% -----------------------------------------------------------------------------
+
+\begin{frame}
+
+> test :: (NumC j, ListC j, Eq j Num, BoolC j, FunC j, MaybeC j)
+> => j (Num -> Num)
+> test = lam (\x -> sum (replicate 3 (2 * 8) ++ replicate 3 8)
+> * maybe 4 (*8) (just (x - 2)))
+
+\pause
+\Large{
+\textcolor{cmnt}{
+\begin{verbatim}
+ghci> (runHaskell test) 3
+576
+\end{verbatim}
+}
+}
+
+\end{frame}
+
+\begin{frame}
+
+> test :: JavaScript (Num -> Num)
+> test = lam (\x -> sum (replicate 3 (2 * 8) ++ replicate 3 8)
+> * maybe 4 (*8) (just (x - 2)))
+
+\pause
+\Large{
+\textcolor{cmnt}{
+\begin{verbatim}
+ghci> Js.compiler test >>=
+ writeFile "test.js"
+\end{verbatim}
+}
+}
+
+\end{frame}
+
+% -----------------------------------------------------------------------------
+
+\begin{frame}
+
+\Huge{\textcolor{strlit}{\tt{JavaScript!}}}
+
+\tiny{
+\textcolor{cmnt}{
+\begin{verbatim}
+var mul = function (v1) { return function (v2) { return v1 * v2; }; }; var fix = function (v1) { return fix
+= arguments.callee, v1(function (i) { return fix(v1)(i) }); }; var list = function (v1) { return function
+(v2) { return function (v3) { return v3.nil ? v1 : v2(v3.head)(v3.tail); }; }; }; var add = function (v1) {
+return function (v2) { return v1 + v2; }; }; var bool = function (v1) { return function (v2) { return
+function (v3) { return v3 ? v1(/*force*/) : v2(/*force*/); }; }; }; var cons = function (v1) { return
+function (v2) { return { head : v1, tail : v2 }; }; }; var sub = function (v1) { return function (v2) {
+return v1 - v2; }; }; var eq = function (v1) { return function (v2) { return v1 == v2; }; }; var maybe =
+function (v1) { return function (v2) { return function (v3) { return v3.nothing ? v1 : v2(v3.just); }; }; };
+var just = function (v1) { return { just : v1 }; }; var c10_11 = list(0); var c10_12 = function (v1) {
+return function (v2) { return c10_11(function (v3) { return function (v4) { return add(v3)(v1(v4)); }; })
+(v2); }; }; var c10_13 = fix(c10_12); var c10_14 = function (v1) { return function (v2) { return v1; }; };
+var c10_15 = c10_14({ nil : 1 }); var c10_16 = function (v1) { return c10_15(v1); }; var c10_17 = bool(
+c10_16); var c10_19 = cons(8); var c10_20 = function (v1) { return function (v2) { return c10_17(function
+(v3) { return c10_14(c10_19(v1(sub(v2)(1))))(v3); })(eq(v2)(0)); }; }; var c10_21 = fix(c10_20); var c10_22
+= c10_21(3); var c10_23 = list(c10_22); var c10_24 = function (v1) { return function (v2) { return c10_23(
+function (v3) { return function (v4) { return cons(v3)(v1(v4)); }; })(v2); }; }; var c10_25 = fix(c10_24);
+var c10_31 = mul(2); var c10_32 = c10_31(8); var c10_33 = cons(c10_32); var c10_34 = function (v1) {
+return function (v2) { return c10_17(function (v3) { return c10_14(c10_33(v1(sub(v2)(1))))(v3); })(eq(v2)
+(0)); }; }; var c10_35 = fix(c10_34); var c10_36 = c10_35(3); var c10_37 = c10_25(c10_36); var c10_38 =
+c10_13(c10_37); var c10_39 = mul(c10_38); var c10_40 = maybe(4); var c10_41 = function (v1) { return
+mul(v1)(8); }; var c10_42 = c10_40(c10_41); var __main = function (v1) { return c10_39(c10_42(just(sub(v1)
+(2)))); };
+\end{verbatim}
+}
+}
+
+\end{frame}
+
+\begin{frame}
+
+\Huge{
+\textcolor{cmnt}{
+\begin{verbatim}
+ alert(__main(3));
+\end{verbatim}
+}
+}
+
+\end{frame}
+
View
@@ -1,18 +1,46 @@
+\definecolor{keyword}{rgb}{0.20,0.60,1.00}
-%format module = "\stress{\textbf{module}}"
-%format where = "\stress{\textbf{where}}"
-%format import = "\stress{\textbf{import}}"
-%format instance = "\stress{\textbf{instance}}"
-%format class = "\stress{\textbf{class}}"
-%format data = "\stress{\textbf{data}}"
-%format if = "\stress{\textbf{if}}"
-%format then = "\stress{\textbf{then}}"
-%format else = "\stress{\textbf{else}}"
-%format let = "\stress{\textbf{let}}"
-%format in = "\stress{\textbf{in}}"
+%format type = "\textcolor{keyword}{\textbf{type}}"
+%format module = "\textcolor{keyword}{\textbf{module}}"
+%format where = "\textcolor{keyword}{\textbf{where}}"
+%format import = "\textcolor{keyword}{\textbf{import}}"
+%format instance = "\textcolor{keyword}{\textbf{instance}}"
+%format class = "\textcolor{keyword}{\textbf{class}}"
+%format data = "\textcolor{keyword}{\textbf{data}}"
+%format if = "\textcolor{keyword}{\textbf{if}}"
+%format then = "\textcolor{keyword}{\textbf{then}}"
+%format else = "\textcolor{keyword}{\textbf{else}}"
+%format let = "\textcolor{keyword}{\textbf{let}}"
+%format in = "\textcolor{keyword}{\textbf{in}}"
%format == = "=="
%format && = "\&\&"
%format || = "||"
%format not = "not"
%format WhiteSpace = "\;"
+\definecolor{cmnt}{rgb}{0.30,0.80,0.30}
+%subst comment a = "\textcolor{cmnt}{\text{\tt-- " a "}}"
+
+\definecolor{strlit}{rgb}{1.00,0.40,0.20}
+%subst string a = "\textcolor{strlit}{\text{\tt\char34" a "\char34}}"
+
+\definecolor{numlit}{rgb}{1.00,0.20,0.20}
+%subst numeral a = "\textcolor{numlit}{\text{" a "}}"
+
+\definecolor{sym}{rgb}{1.00,0.70,0.30}
+%format \ = "\textcolor{sym}{\text{$\lambda$}}"
+%format -> = "\textcolor{sym}{\text{\ $\to$\ }}"
+%format = = "\textcolor{sym}{\text{\ =\ }}"
+%format ++ = "\textcolor{sym}{\text{\ \tt{++}\ }}"
+%format :: = "\textcolor{sym}{\text{\ ::\ }}"
+%format * = "\textcolor{sym}{\text{\ \tt{*}\ }}"
+%format + = "\textcolor{sym}{\text{\ \tt{+}\ }}"
+%format - = "\textcolor{sym}{\text{\ \tt{-}\ }}"
+%format == = "\textcolor{sym}{\text{\ \tt{==}\ }}"
+%format => = "\textcolor{sym}{\text{\ $\Rightarrow$\ }}"
+%format && = "\textcolor{sym}{\text{\ $\land$\ }}"
+%format || = "\textcolor{sym}{\text{\ $\lor$\ }}"
+%format :-> = "\textcolor{sym}{\text{\ $\mapsto$\ }}"
+%format . = "\textcolor{sym}{\text{\ $\circ$\ }}"
+%format $ = "\textcolor{sym}{\text{\ $\$$\ }}"
+
@@ -34,12 +34,14 @@
\newcommand{\stress}[1]{\textcolor{stress}{#1}}
+\definecolor{subtitle}{rgb}{0.30,0.80,0.30}
+
% -----------------------------------------------------------------------------
\begin{document}
-\title{AwesomePrelude}
-\subtitle{``Liberating Haskell from data types!''}
+\title{\LARGE{\texttt{AWESOME PRELUDE}}}
+\subtitle{\textcolor{subtitle}{``Liberating Haskell from datatypes!''}}
\author{Tom Lokhorst, Sebastiaan Visser}
\date{\today}
@@ -61,5 +63,11 @@
\include{RealExpr}
+% ------------------ BREAK ---------------
+
+\include{Value}
+
+\include{Conclusion}
+
\end{document}

0 comments on commit 20269de

Please sign in to comment.