Commit b985bb1b authored by Michael Hanus's avatar Michael Hanus
Browse files

libs and tools updated

parent 5dc08443
......@@ -15,7 +15,12 @@ this version contains the following changes:
* Some libraries removed since they are available as packages
which can easily be installed via `cpm`:
- `Assertion`
(no longer used since `currytest` has been replaced by `currycheck`)
- `CLP*` (now in package `clp-pakcs`)
- `CSV` (now available as `Text.CSV` in package `csv`)
- `Parser` (now available in package `fl-parser`)
- `RegExp` (now available in package `regexp`)
Release notes for PAKCS Version 1.15.0 (October 11, 2017)
......
Subproject commit 543ddf413b27cf45b5aa51dd64b873bfcb6c32fa
Subproject commit 4a45453283a22c69e55e45243c5e8eca6555ba58
......@@ -266,14 +266,6 @@ h [1,3]
False
h [2,((_impl#div#Prelude.Integral#Prelude.Int) 1) 0]
False
Loading program "expr_parser"...
((expression val) "(10+5*2)/4") =:= []
{val=5} True
Loading program "palindrome"...
(pali "abaaba") =:= []
True
pali5
["aaaaa","aabaa","ababa","abbba","baaab","babab","bbabb","bbbbb"]
Loading program "accountport"...
goal1 b
{b=250} True
......
---------------------------------------------------------------------------
-- A simple example for the use of the functional logic parser combinators:
-- We define a parser for arithmetic expressions over natural numbers.
-- The presentation of this parser is the value of the expression.
import Parser
import Char
expression = term t <*> plus_minus op <*> expression e >>> (op t e)
<||> term
where op,t,e free
term = factor f <*> prod_div op <*> term t >>> (op f t)
<||> factor
where op,f,t free
factor = terminal '(' <*> expression e <*> terminal ')' >>> e
<||> num
where e free
plus_minus = terminal '+' >>> (+)
<||> terminal '-' >>> (-)
prod_div = terminal '*' >>> (*)
<||> terminal '/' >>> div
num = some digit l >>> numeric_value l
where l free
numeric_value ds = foldl1 ((+) . (10*)) (map (\c->ord c - ord '0') ds)
digit = satisfy isDigit
-- example application: expression val "(10+5*2)/4" =:= [] where val free
---------------------------------------------------------------------------
-- A simple example for the use of the functional logic parser combinators:
--
-- A parser for palindromes over the alphabet 'a' and 'b'
import Parser
import AllSolutions
-- Terminals:
a = terminal 'a'
b = terminal 'b'
-- Palindromes:
pali = empty <|> a <|> b <|> a<*>pali<*>a <|> b<*>pali<*>b
{-
Examples:
Check correctness of a sentence:
> pali "abaaba" =:= []
Generate palindromes:
> pali [x,y,z] =:= [] where x,y,z free
-}
-- Generate list of all palindromes of length 5:
pali5 = getAllSolutions (\[x1,x2,x3,x4,x5] -> pali [x1,x2,x3,x4,x5] =:= [])
-- Generate palindromes of a given length:
palin len = getAllSolutions (\xs -> strlen xs len & pali xs =:= [])
where
-- Has a list a given length?
strlen [] 0 = True
strlen (_:xs) n | n>0 = strlen xs (n-1)
......@@ -102,13 +102,6 @@ g (Just "ab")
h [1,2]
h [1,3]
h [2,div 1 0]
:cd parsing
:l expr_parser
expression val "(10+5*2)/4" =:= [] where val free
:l palindrome
pali "abaaba" =:= []
pali5
:cd ..
:cd distcurry
:l accountport
goal1 b where b free
......
-- Examples for the currytest tool
-- In order to use the tool, one has to import the library Assertion
-- which contains the definition of the type of assertions:
import Assertion
-- Now we can test properties of our program:
-- A test is any top-level function of type "Assertion".
-- All functions of this type are considered by the tester
-- provided that they are exported by the module.
-- Note that we state some (logically wrong) assertions in order
-- to show the output of failures with the test tool.
-- This test should succeed:
test1 = assertEqual "++" ([1,2]++[3,4]) [1,2,3,4]
-- This test should fail:
test2 = assertEqual "head 1" (head [2]) 1
-- This test should fail (no solution):
test3 = assertEqual "head 2" (head []) []
-- This test should fail:
test4 = assertTrue "null test" (null [1])
-- This test should fail (provided that there is no file "xxxx"):
test5 = assertIO "IO test" (readFile "xxxx") ""
Subproject commit 065d35c441ab55c1a8cad3ff8768b9982c9ba4b3
Subproject commit 55c120401e5b37ca02c89dd9d6d79b7268a518f3
{-# OPTIONS_CYMAKE -F --pgmF=currypp --optF=foreigncode #-}
------------------------------------------------------------------------------
--- This program contains some examples for integrated code to support
--- regular expression matching.
--- The syntax of regular expression is similar to
--- POSIX extended regular expressions
------------------------------------------------------------------------------
import RegExp -- required in the pre-processed program
import Test.EasyCheck
check1 :: Bool
check1 = match ``regex abc'' "abc"
testCheck1 = always check1
check2 :: Bool
check2 = match ``regex aba*c'' "abaaaaaaaaaaaaac"
testCheck2 = always check2
check3 :: String -> Bool
check3 = match ``regex (a|(bc*))+''
testCheck3a = always (check3 "abcccbccca")
testCheck3b = always (not (check3 "abcccbcccac"))
check4 :: String -> Bool
check4 = match ``regex [:alpha:]''
testCheck4a = always (check4 "a")
testCheck4b = always (check4 "A")
testCheck4c = always (not (check4 "0"))
testCheck4d = always (not (check4 "ab"))
check5 :: String -> Bool
check5 = match ``regex [a-z]+''
testCheck5a = always (check5 "a")
testCheck5b = always (check5 "abc")
testCheck5c = always (not (check5 "abc42"))
testCheck5d = always (not (check5 ""))
-- Tests with parameterized regular expressions:
pregexp1 :: Ord a => a -> a -> [a] -> Bool
pregexp1 v1 v2 = match ``regex [<v1>-<v2>]*''
testPregexp1a = always (pregexp1 'a' 'z' "abc")
testPregexp1b = always (pregexp1 'A' 'Z' "ABC")
testPregexp1c = always (not (pregexp1 'A' 'Z' "abc"))
pregexp2 :: Ord a => a -> a -> [a] -> Bool
pregexp2 v1 v2 = match ``regex (<v1>|<v2>)*''
testPregexp2a = always (pregexp2 'a' 'b' "abaabbb")
testPregexp2b = always (not (pregexp2 'a' 'z' "abaabbb"))
-- A regular expression containing a complex Curry expression:
check6 :: Bool
check6 = match ``regex <((\x -\> x) 'a')>'' "a"
testCheck6 = always check6
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment