source: sizechecking/trunk/README.txt @ 18

Last change on this file since 18 was 18, checked in by gobi, 11 years ago

creating a branch

File size: 3.6 KB
Line 
1Prerequisites
2-------------
3
4You need at least version 2011.4.0.0 of the Haskell platform, an installed
5[Z3](http://research.microsoft.com/en-us/um/redmond/projects/z3/)
6and the packages `sbv` and `value-supply`. If you have a working Haskell platform installed you can
7install value-supply by typing
8
9        cabal install value-supply sbv
10
11
12Source files
13------------
14
15Examples.hs
16  ~ Some examples
17SizedExp.hs
18  ~ Embedded language to prove size expressions
19Lambda.hs
20  ~ Size expressions
21Constraints.hs
22  ~ Constraint solver
23
24Using the examples
25------------------
26
27~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28$ ghci Examples.hs
29GHCi, version 7.0.4: http://www.haskell.org/ghc/  :? for help
30Loading package ghc-prim ... linking ... done.
31Loading package integer-gmp ... linking ... done.
32Loading package base ... linking ... done.
33Loading package ffi-1.0 ... linking ... done.
34[1 of 4] Compiling Lambda           ( Lambda.hs, interpreted )
35[2 of 4] Compiling Constraints      ( Constraints.hs, interpreted )
36[3 of 4] Compiling SizedExp         ( SizedExp.hs, interpreted )
37[4 of 4] Compiling Main             ( Examples.hs, interpreted )
38Ok, modules loaded: Lambda, SizedExp, Constraints, Main.
39*Main>
40~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
41
42Type "`runTests`" to run all test cases or type "`prove map`" to prove the
43function named map.
44
45Under Windows
46-------------
47It is not perfect, and you will see a box after every special character, but at
48least it works.
49
50 - Open a console by running the program `cmd`
51 - Issue the command `chcp 65001`
52 - In the console cd to the trunk directory
53 - Now, you can run `ghci Examples.hs`
54
55
56Introduction to Haskell syntax
57------------------------------
58
59Haskell syntax is very much like Clean, however there are some expressions you
60cannot find in Clean.
61
62### Backtick ###
63
64Every haskell function can be used as infix operator. For example the
65following two expressions are the same.
66
67~~~~~~~~~~~
68func a b
69a `func` b
70~~~~~~~~~~~
71
72### Dollar ###
73
74Dollar sign is just explicit application (but with different precedence), so it
75can be used as a backward pipe operator. The following expressions are the
76same.
77
78~~~~~~~~~~~~~~
79func (a b)
80func $ a b
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 that we do not want to prove that
133branch.
Note: See TracBrowser for help on using the repository browser.