packages feed

LambdaShell 0.9 → 0.9.1

raw patch · 4 files changed

+35/−304 lines, 4 filesdep +containersdep ~basedep ~haskell98dep ~mtl

Dependencies added: containers

Dependency ranges changed: base, haskell98, mtl, parsec, readline

Files

LambdaShell.cabal view
@@ -1,5 +1,7 @@ Name:            LambdaShell-Version:         0.9+Cabal-Version:   >= 1.2+Build-Type:	 Simple+Version:         0.9.1 License:         GPL License-file:    LICENSE Author:          Robert Dockins@@ -7,26 +9,33 @@ Stability:       Beta Category:        Compilers/Interpreters Synopsis:        Simple shell for evaluating lambda expressions+Homepage:        http://www.cs.princeton.edu/~rdockins/lambda/home/ Description:   The lambda shell is a feature-rich shell environment and command-line tool for   evaluating terms of the pure, untyped lambda calculus.  The Lambda   Shell builds on the shell creation framework Shellac, and showcases   most of Shellac's features.-Build-Depends:-    base >= 1.0,-    haskell98 >= 1.0,-    parsec >= 1.0,-    mtl >= 1.0,-    readline >= 1.0,-    Shellac >= 0.9,-    Shellac-readline >= 0.9 -Executable:      lambdaShell-Main-Is:         main.hs-Hs-Source-Dirs:-    src-Extensions:-    MultiParamTypeClasses-Extra-libraries:-    readline-GHC-Options: -O+Executable lambdaShell+  Main-Is: main.hs+  Hs-Source-Dirs: src+  Other-Modules:+     CPS+     Env+     Lambda+     LambdaCmdLine+     LambdaParser+     LambdaShell+     Version+  Extensions:+     MultiParamTypeClasses+  Extra-libraries:+     readline+  GHC-Options: -O+  Build-Depends:+     base, haskell98, parsec,+     mtl, readline,+     Shellac >= 0.9,+     Shellac-readline >= 0.9+  if impl( ghc >= 6.8 )+     Build-Depends: containers
− README
@@ -1,123 +0,0 @@--  The Lambda Shell--==================---== What is it?--It is a feature-rich shell environment and command-line tool for-evaluating terms of the pure, untyped lambda calculus.  The Lambda-Shell builds on the shell creation framework Shellac, and showcases-most of Shellac's features.--Features:-  -- evalutate lambda terms directly from the shell prompt using-     normal or applicative order.  In normal order, one can evaluate-     to normal form, head normal form, or weak head normal form.-  -- define aliases for lambda terms using a top level, non-recursive-     'let' construct.-  -- Show traces of term evaluation, or dump the trace to a file-  -- Count the number of reductions when evaluating terms-  -- test two lambda terms for confluence (that is; if two-     terms, when evaluated to normal form, are alpha equivalant)-  -- programs can be entered from the command line (using the -e option)-     or piped into stdin (using the -s option)-  -- perform Continuation Passing Style (CPS) transforms on terms before-     evaluation using the syntax  '[[ five ]]'---An example session:----------------------------------$ lambdaShell--The Lambda Shell, version 0.3-Copyright 2005-2006, Robert Dockins---The Lambda Shell comes with ABSOLUTELY NO WARRANTY; for details-type ':nowarranty'.  This is free software, and you are welcome to-redistribute it under certain conditions; type ':gpl'-for details--> (\x y. x) (\a. a) (\b. b)-\a. a-> :load prelude.lam-> :show four-four = succ three-> four-\f x. f (f (f (f x)))-> mul two three-\f x. f (f (f (f (f (f x)))))-> let x = plus six two-> x == eight-equal-> x == nine-not equal-> one-\f x. f x-> [[ one ]]-\f k. k (\x k_0. f x k_0)-> :showcount-showcount on-> sub seven two-\f x. f (f (f (f (f x))))-<<90 reductions>>-> let l = insertSort (cons two (cons three (cons one nil)))-> index zero l-one-<<463 reductions>>-> index one l-two-<<2135 reductions>>-> index two l-three-<<5720 reductions>>-> :quit-----------------------------------------------------== Why do I care?--Because you are a lambda calculus nut, and you just can't get enough.-Or, the lambda shell could be a worthwhile teaching tool.  The command-line features (especially confluence testing) could lend themselves to-automatic grading.  Also, the lambda shell is a good example of-how to write a shell using Shellac.----== How is it licensed?--The Lambda Shell is licensed under the GNU GPL version 2.  See-the LICENSE file for details.----== How do I build it?--The lambda shell uses a Cabal build system.  The follwing-commands assume you have a haskell interpreter in your system-path named 'runhaskell'.  All commands are run from-this directory.  If Shellac is installed as a user package, you-will need to add the '--user' flag to your configure commands.--To install for the whole system:--runhaskell Setup.hs configure-runhaskell Setup.hs build-runhaskell Setup.hs install--To install for a single user:--runhaskell Setup.hs configure --prefix=/home/<username>-runhaskell Setup.hs build-runhaskell Setup.hs install --user---== Who is responsable for this mess?--You can send bug reports, rants and comments to:--  Robert Dockins <robdockins AT fastmail.fm>
− prelude.lam
@@ -1,155 +0,0 @@-# the church encoding for booleans-true    = \t f. t;-false   = \t f. f;-if      = \b x y. b x y;-not     = \x.   if x false true;-and     = \x y. if x y false;-or      = \x y. if x true y;-xor     = \x y. if x (not y) y;--# the church encoding for peano numbers-zero    = \f x. x;-succ    = \n f x. f (n f x);-pred    = \n f x. n (\g h. h (g f)) (\u. x) (\u. u);--# addition, subtraction and multiplication-plus    = \m n f x. m f (n f x);-sub     = \m n. (n pred) m;-mul     = \m n f. m (n f);--# some useful predicates on church numerals-even    = \n. n not true;-iszero  = \m. m (\x. false) true;-lte     = \m n. iszero (sub m n);-gte     = \m n. iszero (sub n m);-eq      = \m n. and (lte m n) (gte m n);-lt      = \m n. and (lte m n) (not (gte m n));-gt      = \m n. and (gte m n) (not (lte m n));--# aliases for the church numerals up to ten-one   = succ zero;-two   = succ one;-three = succ two;-four  = succ three;-five  = succ four;-six   = succ five;-seven = succ six;-eight = succ seven;-nine  = succ eight;-ten   = succ nine;--# integer exponentation-pow     = \m n. n (\x. mul m x) one;---# Turner's combinators-I = \x .x;-K = \x y. x;-S = \f g x. (f x) (g x);-W = \f x. f x x;-B = \f g x. f (g x);-C = \f x y. f x y;--# the fixpoint combinator-Y = \f. (\x. f (x x)) \x. f (x x);--# a divergent labmda term-omega = (\x. x x) \x. x x;--# factorial-fac = Y (\facF n. if (iszero n)-                     one -                     (mul n (facF (pred n))));--# the church encoding for pairs-pair = \x y f. f x y;-fst  = \p. p (\x y. x);-snd  = \p. p (\x y. y);--# now, encode ADTs-match = \x pats. x (\n f. f (fst ((n snd) pats)));--# the ADT representation of lists-nil  = \    w. w zero (\f. f);-cons = \h t w. w one  (\f. f h t);--# head and tail, by pattern matching-head = \l. match l (pair nil-                   (pair (\h t. h)-                    zero));--tail = \l. match l (pair nil-                   (pair (\h t. t)-                    zero));--# the ith element of a list-index = \n l. head (n tail l);--# right fold on a list-foldr = \f z. Y (\foldF l. match l (pair z-                                   (pair (\h t. f h (foldF t))-                                    zero)));--# left fold on a list-foldl = \f. Y (\foldF r l. match l (pair r-                                   (pair (\h t. foldF (f r h) t)-                                    zero)));--# the length of a list-len = foldl (\x h. succ x) zero;--# the mapping function on a list-map = \f. Y (\mapF l. match l (pair nil-                              (pair (\h t. cons (f h) (mapF t))-                               zero)));--# list generator-unfold = \g until. Y (\unfoldF x. if (until x)-                                       (cons x nil)-                                       (cons x (unfoldF (g x))));--# some other interesting list functions....--iterate = \g. unfold g (K false);-nats = iterate succ zero;--upTo = \n. unfold succ (\x. gte x n) zero;--zipWith = \f. Y (\zipF l1 l2. match l1-                     (pair nil-                     (pair (\h1 t1. match l2-                        (pair nil-                        (pair (\h2 t2.-                           cons (f h1 h2) (zipF t1 t2))-                         zero)))-                       zero)));--zip = zipWith pair;--take = \n l. zipWith K l (tail (upTo n));-drop = \n l. n tail l;--minAux = foldl (\x y. if (lt y x) y x);--min  = \l. match l-             (pair nil-             (pair minAux-              zero));--maxAux = foldl (\x y. if (gt y x) y x);--max  = \l. match l-             (pair nil-             (pair maxAux-              zero));--remove = \x. Y (\removeF l. match l-              (pair nil-              (pair (\h t.-                 if (eq h x) t (cons h (removeF t)))-               zero)));--insertSort = Y (\sortF l. match l-             (pair nil-             (pair (\h t. (\x. cons x (sortF (remove x l))) (minAux h t))-              zero)));
src/Version.hs view
@@ -41,7 +41,7 @@  noWarranty :: String   noWarranty = unlines-  [ "			    NO WARRANTY"+  [ "                       NO WARRANTY"   , ""   , "  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY"   , "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN"@@ -66,15 +66,15 @@  gpl :: String gpl = unlines-  ["		    GNU GENERAL PUBLIC LICENSE"-  ,"		       Version 2, June 1991"+  ["                GNU GENERAL PUBLIC LICENSE"+  ,"                   Version 2, June 1991"   ,""   ," Copyright (C) 1989, 1991 Free Software Foundation, Inc."   ,"                       51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA"   ," Everyone is permitted to copy and distribute verbatim copies"   ," of this license document, but changing it is not allowed."   ,""-  ,"			    Preamble"+  ,"                        Preamble"   ,""   ,"  The licenses for most software are designed to take away your"   ,"freedom to share and change it.  By contrast, the GNU General Public"@@ -124,7 +124,7 @@   ,"  The precise terms and conditions for copying, distribution and"   ,"modification follow."   ,""-  ,"		    GNU GENERAL PUBLIC LICENSE"+  ,"                GNU GENERAL PUBLIC LICENSE"   ,"   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION"   ,""   ,"  0. This License applies to any program or other work which contains"@@ -323,7 +323,7 @@   ,"of preserving the free status of all derivatives of our free software and"   ,"of promoting the sharing and reuse of software generally."   ,""-  ,"			    NO WARRANTY"+  ,"                        NO WARRANTY"   ,""   ,"  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY"   ,"FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN"@@ -345,9 +345,9 @@   ,"PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE"   ,"POSSIBILITY OF SUCH DAMAGES."   ,""-  ,"		     END OF TERMS AND CONDITIONS"+  ,"                 END OF TERMS AND CONDITIONS"   ,""-  ,"	    How to Apply These Terms to Your New Programs"+  ,"        How to Apply These Terms to Your New Programs"   ,""   ,"  If you develop a new program, and you want it to be of the greatest"   ,"possible use to the public, the best way to achieve this is to make it"