packages feed

egison-tutorial 3.5.1 → 3.5.9

raw patch · 2 files changed

+28/−27 lines, 2 filesdep −strict-iodep ~egison

Dependencies removed: strict-io

Dependency ranges changed: egison

Files

Main.hs view
@@ -300,7 +300,7 @@     Content "Try to calculate '1 + 1/2 + 1/3 + 1/4 + ... + 1/100'.\nRemember that we can convert a rational number to a float number with 'rtof'."      ["(rtof 2/3)"]      [],-    Content "Try to calculate '1 + (1/2)^2 + (1/3)^2 + (1/4)^2 + ... + (1/100)^2'.\nIn fact, '1 + (1/2)^2 + (1/3)^2 + (1/4)^2 + ...' converges to '(/ (power pi 2) 6)'.\nPlease observe that."+    Content "Try to calculate '1 + (1/2)^2 + (1/3)^2 + (1/4)^2 + ... + (1/100)^2'.\nIn fact, '1 + (1/2)^2 + (1/3)^2 + (1/4)^2 + ...' converges to '(/ (power pi 2) 6)'."      []      [],     Content "This is the end of this section.\nPlease play freely or proceed to the next section.\nThank you for enjoying our tutorial!"@@ -337,7 +337,7 @@      ["(take 100 (zip nats nats))", "(take 100 (zip primes primes))"]      ["Try to generate the prime table that is like '{[1 2] [2 3] [3 5] [4 7] [5 11] ...}'"],     Content "Try to create a fibonacci sequence that is like '{1 1 2 3 5 8 13 21 34 55 ...}'.\n\nHint:\n  Replace '???' in the following expression to a proper function.\n  (define $fibs {1 1 @(map ??? (zip fibs (cdr fibs)))})"-     [""]+     []      [],     Content "This is the end of this section.\nPlease play freely or proceed to the next section.\nThank you for enjoying our tutorial!"      []@@ -345,7 +345,7 @@     ],   Section "Basics of pattern-matching                    (10 minutes)"    [-    Content "We can pattern-match against a collection.\nThe 'join' pattern divides a collection into two collections.\nPlease note that the 'match-all' expression enumerates all results of pattern-matching."+    Content "Let's try pattern-matching against a collection.\nThe 'join' pattern divides a collection into two collections.\nPlease note that the 'match-all' expression enumerates all results of pattern-matching."      ["(match-all {1 2 3}     (list integer) [<join $hs $ts> [hs ts]])",       "(match-all {1 2 3 4 5} (list integer) [<join $hs $ts> [hs ts]])"]      [],@@ -357,27 +357,36 @@      ["(match-all {1 2 3}     (list integer) [<cons $x  _>  x])",       "(match-all {1 2 3 4 5} (list integer) [<join $hs _> hs])"]      [],-    Content "We can write non-linear patterns.\nIn the following case, patterns that begins with ',' matches the object only if the object is equal with the expression after ','.\nPlease try the following expression."-     ["(match-all {1 1 2 2 3 2} (list integer) [<join _ <cons $x <cons ,x _>>> x])",-      "(match-all {1 2 2 3 3 2} (list integer) [<join _ <cons $x <cons ,x _>>> x])"]+    Content "We can write non-linear patterns.\nNon-linear pattern is a pattern that allows multiple occurrence of same variables in a pattern.\nPatterns that begins with ',' matches the object when it is equal with the expression after ','."+     ["(match-all {1 1 2 3 3 2} (list integer) [<join _ <cons $x <cons ,x _>>> x])",+      "(match-all {1 1 2 3 3 2} (list integer) [<join _ <cons $x <cons ,(+ x 1) _>>> x])"]      [],-    Content "We can express various things using 'cons' and 'join'.\nThe most of functions in the collection library of Egison are written using pattern-matching!"-     ["(match-all {1 1 2 3 2} (list integer) [<join _ <cons $x <join _ <cons $y _>>>> [x y]])",-      "(match-all {1 1 2 3 2} (list integer) [<join _ <cons $x <join _ <cons ,x _>>>> [x x]])"]-     ["Try to enumerate three combinations of numbers."],-    Content "We can pattern-match against infinite collections.\nWe can enumerate twin primes using pattern-matching as follow.\nNote that we can write any expression after ','."+    Content "We can pattern-match against infinite collections.\nWe can enumerate twin primes using pattern-matching as follow."      ["(take 10 (match-all primes (list integer) [<join _ <cons $p <cons ,(+ p 2) _>>> [p (+ p 2)]]))"]      ["What is the 100th twin prime?"],     Content "Try to enumerate the first 10 prime pairs whose form is (p, p+6) like '{{[5 11] [7 13] [11 17] [13 19] [17 23] ...}'."      []      [],+    Content "A pattern that has '^' ahead of which is called a not-pattern.\nA not-pattern matches when the target does not match against the pattern."+     ["(match-all {1 1 2 2 3 4 4 5} (list integer) [<join _ <cons $x <cons  ,x _>>> x])",+      "(match-all {1 1 2 2 3 4 4 5} (list integer) [<join _ <cons $x <cons ^,x _>>> x])"]+     [],+    Content "A pattern whose form is '(& p1 p2 ...)' is called an and-pattern.\nAn and-pattern is a pattern that matches the object, if and only if all of the patterns are matched.\nAnd-pattern is used like an as-pattern in the following sample."+     ["(match-all {1 2 4 5 6 8 9} (list integer) [<join _ <cons $x <cons (& ^,(+ x 1) $y) _>>> [x y]])"]+     [],+    Content "A pattern whose form is '(| p1 p2 ...)' is called an or-pattern.\nAn or-pattern matches with the object, if the object matches one of given patterns.\nUsing it, We can enumerate prime triplets."+     ["(take 10 (match-all primes (list integer) [<join _ <cons $p <cons (& $m (| ,(+ p 2) ,(+ p 4))) <cons ,(+ p 6) _>>>> [p m (+ p 6)]]))"]+     ["What is the 20th prime triplet?"],+    Content "Try to enumerate the first 8 prime quadruplets whose form is (p, p+2, p+6, p+8) like '{{[5 7 11 13] [11 13 17 19] ...}'."+     []+     [],     Content "This is the end of this section.\nPlease play freely or proceed to the next section.\nThank you for enjoying our tutorial!"      []      []     ],   Section "Pattern-matching against various data types   (10 minutes)"    [-    Content "We can pattern-match even against multisets and sets.\nWe can change the way of pattern-matching by changing the \"matcher\".\nPlease try the following expressions."+    Content "We can also pattern-match against multisets and sets.\nWe can change the way of pattern-matching by just changing a matcher."      ["(match-all {1 2 3} (list integer)     [<cons $x $xs> [x xs]])",       "(match-all {1 2 3} (multiset integer) [<cons $x $xs> [x xs]])",       "(match-all {1 2 3} (set integer)      [<cons $x $xs> [x xs]])"]@@ -387,28 +396,20 @@       "(match-all {1 2 3 4 5} (multiset integer) [<join $xs $ys> [xs ys]])",       "(match-all {1 2 3 4 5} (set integer)      [<join $xs $ys> [xs ys]])"]      [],-    Content "We can write non-linear patterns.\nTry the following expression."+    Content "Try non-linear pattern-matching against multiset."      ["(match-all {1 1 2 3 2} (multiset integer) [<cons $x <cons ,x       _>> x])",-      "(match-all {1 1 2 3 2} (multiset integer) [<cons $x <cons ,(+ x 2) _>> x])"]-     [],-    Content "A pattern that has '^' ahead of which is called a not-pattern.\nA not-pattern matches when the target does not match against the pattern."-     ["(match-all {1 2 1 3 2} (multiset integer) [<cons $x  <cons ,x _>> x])",+      "(match-all {1 1 2 3 2} (multiset integer) [<cons $x <cons ,(+ x 2) _>> x])",       "(match-all {1 2 1 3 2} (multiset integer) [<cons $x ^<cons ,x _>> x])"]      [],-    Content "We can pattern-match against infinite collections with infinite results.\nNote that Egison really enumerates all pairs of two natural numbers in the following example."-     ["(take 10 (match-all nats (set integer) [<cons $m <cons $n _>> [m n]]))"]+    Content "The following samples enumerate pairs and triplets of natural numbers.\nNote that Egison really enumerates all results."+     ["(take 10 (match-all nats (set integer) [<cons $m <cons $n _>>           [m n]]))",+      "(take 10 (match-all nats (set integer) [<cons $l <cons $m <cons $n _>>> [l m n]]))"]      [],     Content "This is the end of our tutorial.\nThank you for enjoying our tutorial!\nPlease check our paper, manual and code for further reference!"      []      []     ]   ]---    Content "We support \"and-patterns\" and \"or-patterns\".\nWe can enumerate prime triplets using them as follow.\n\"And-patterns\" and \"or-patterns\" are represented using '&' and '|' respectively."---     ["(take 10 (match-all primes (list integer) [<join _ <cons $p <cons (& $m (| ,(+ p 2) ,(+ p 4))) <cons ,(+ p 6) _>>>> [p m (+ p 6)]]))"]---     ["What is the 20th prime triplet?"],---    Content "Try to enumerate the first 8 prime quadruplets whose form is (p, p+2, p+6, p+8) like '{{[5 7 11 13] [11 13 17 19] ...}'."---     []---     [], --  Section "Define your own functions" --   [ --    Content "Did we think how about \"n\" combinations of the elements of the collection?\nWe already have a solution.\nWe can write a pattern that include '...' as the following demonstrations."
egison-tutorial.cabal view
@@ -1,5 +1,5 @@ Name:                egison-tutorial-Version:             3.5.1+Version:             3.5.9 Synopsis:            A tutorial program for the Egison programming language Description:         A tutorial program for the Egison programming language.                      Egison is the programming langugage that realized non-linear pattern-matching against unfree data types.@@ -20,4 +20,4 @@  Executable egison-tutorial   Main-is:             Main.hs-  Build-depends:       egison >= 3.5.1, base >= 4.0 && < 5, array, containers, unordered-containers, haskeline, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, filepath, regex-posix, strict-io, bytestring+  Build-depends:       egison >= 3.5.9, base >= 4.0 && < 5, array, containers, unordered-containers, haskeline, transformers, mtl, parsec >= 3.0, directory, ghc, ghc-paths, filepath, regex-posix, bytestring