diff options
author | Camil Staps | 2016-03-30 10:54:45 +0200 |
---|---|---|
committer | Camil Staps | 2016-03-30 11:25:31 +0200 |
commit | 25681f822f4a965ca38efa47eed9927b0edc75c7 (patch) | |
tree | 3d7b1bd603f83f5a5f4faff85939dd397beb67c2 /README.md | |
parent | Readme: features, headings (diff) |
Overloaded state, more boolean ops, unaliased Var
Diffstat (limited to 'README.md')
-rw-r--r-- | README.md | 27 |
1 files changed, 14 insertions, 13 deletions
@@ -17,23 +17,26 @@ For example, the [following program][sqrt] is a rounded down square root function (if `x=n` at the start and `n` is a natural number, then `z` is the square root of `n`, rounded down, after execution): + import While + from WhileVars import o, s, x, z // o :== Var 'o'; etc. + sqrt :: Stm - sqrt = 'z' := 0 :. - 'o' := 1 :. - 's' := 1 :. - While ('s' <= 'x') - ( 'z' := 'z' + 1 :. - 'o' := 'o' + 2 :. - 's' := 's' + 'o' ) + sqrt = z := 0 :. + o := 1 :. + s := 1 :. + While (s <= x) + ( z := z + 1 :. + o := o + 2 :. + s := s + o ) ### Evaluation -We can now execute this code on a `State`, which maps `Var` (`Char`) to `Int`: +We can now execute this code on a `State`, which maps `Var` to `Int`: Start :: Int - Start = eval NS sqrt st 'z' + Start = eval NS sqrt st z where - st :: Var -> Int - st 'x' = 36 + st :: Char -> Int // Or: st :: Var -> Int // st :: CharState + st 'x' = 9 // st (Var 'x') = 9 // st = \'x' -> 9 `eval NS sqrt st` is a `State` itself (the state that results from execution of `sqrt` in `st`), so we apply that to `z` to get the result. Other than the @@ -135,8 +138,6 @@ qualified imports where needed. ## Todo - Gast testing - - More boolean operators for testing integers besides `==` and `<=` - - Can boolean operators be made functions rather than type constructors? - Prettyprint for `DerivTree` - Parser - Add the state to the `toString` of `DerivTree` and `DerivSeq` |