source: sizechecking/README.txt @ 6

Last change on this file since 6 was 5, checked in by gobi, 13 years ago

size checking

File size: 3.5 KB
Line 
1Prerequisites
2-------------
3
4You need at least version 2011.4.0.0 of haskell platform and the package
5value-supply. If you have haskell platform installed you can install
6value-supply by typing
7
8        cabal install value-supply
9
10
11Source files
12------------
13
14Examples.hs
15  ~ Some examples
16SizedExp.hs
17  ~ Embedded language to prove size expressions
18Lambda.hs
19  ~ Size expressions
20Constraints.hs
21  ~ Constraint solver
22
23Using the examples
24------------------
25
26~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
27$ ghci Examples.hs
28GHCi, version 7.0.4: http://www.haskell.org/ghc/  :? for help
29Loading package ghc-prim ... linking ... done.
30Loading package integer-gmp ... linking ... done.
31Loading package base ... linking ... done.
32Loading package ffi-1.0 ... linking ... done.
33[1 of 4] Compiling Lambda           ( Lambda.hs, interpreted )
34[2 of 4] Compiling Constraints      ( Constraints.hs, interpreted )
35[3 of 4] Compiling SizedExp         ( SizedExp.hs, interpreted )
36[4 of 4] Compiling Main             ( Examples.hs, interpreted )
37Ok, modules loaded: Lambda, SizedExp, Constraints, Main.
38*Main>
39~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
40
41Type "`runTests`" to run all test cases or type "`prove map`" to prove the
42function named map.
43
44Under Windows
45-------------
46It is not perfect, and you will see a box after every special character, but at
47least it works.
48
49 - Open a console by running the program `cmd`
50 - Issue the command `chcp 65001`
51 - In the console cd to the trunk directory
52 - Now, you can run `ghci Examples.hs`
53
54
55Introduction to Haskell syntax
56------------------------------
57
58Haskell syntax is very much like Clean, however there are some expressions you
59cannot find in Clean.
60
61### Backtick ###
62
63Every haskell function can be used as infix operator. For example the
64following two expressions are the same.
65
66~~~~~~~~~~~
67func a b
68a `func` b
69~~~~~~~~~~~
70
71### Dollar ###
72
73Dollar sign is just explicit application (but with different precedence), so it
74can be used as a backward pipe operator. The following expressions are the
75same.
76
77~~~~~~~~~~~~~~
78func (a b)
79func $ a b
80~~~~~~~~~~~~~~
81
82
83
84The Embedded Language
85---------------------
86
87As an example the function `map` is examined.
88
89~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
901 smap  = Abs 5 $ AAbs 18 6 $ List (Var 18) (Abs 8$ App (Var 5) (App (Var 6) (Var 8)))
912 map :: (SizedExp se)  => Size se ( (a->b) -> [a] -> [b] )
923 map = bind smap body
934     where body f l = match l (nil)
945             ( \x xs ->  cons `app` (f `app` x) `app` (map `app` f `app` xs ))
95~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
96
97Here line 3 tells us map is a top-level binding, where the body of the function is
98defined in line 4--5 and its size expression is in line 1. Unfortunately the
99size expression language has not yet been embedded, so it is a bit difficult to
100read. Type `smap` in the GHC console to get a pretty printed form.
101
102~~~~~~~~~~~~~~~~~
103*Main> smap
104λf.Λs,g.List s (λi.f (g i))
105~~~~~~~~~~~~~~~~~
106
107The type of the function tells us the underlying type, ie. `(a->b) -> [a] -> [b]`.
108
109The body of map corresponds to the following expression
110
111~~~~~~~~~~~~~~~~~~~~~~~
112match l of
113   nil       -> nil
114   cons x xs -> cons (f x) (map f xs)
115~~~~~~~~~~~~~~~~~~~~~~~
116
117
118In the embedded language `bind`, `match` and `app` are supercombinators.
119
120`bind sexp exp`
121
122  : combines a size and an expression and creates a top-level binding
123
124`match list nilexp consexp`
125
126  : embedding of the match operator of our language to haskell
127
128`app exp1 exp2`
129
130  : embedding of the function application of our language to haskell
131
132There is also a function called `true` to denote we do not want to prove that
133branch.
134
135
Note: See TracBrowser for help on using the repository browser.