Commit f5b6dd94 by Kai-Oliver Prott

### Merge remote-tracking branch 'origin/master' into version3

parent 4f063fa5
 ... ... @@ -47,10 +47,14 @@ toLower c | isUpper c = chr (ord c - ord 'A' + ord 'a') --- Converts a (hexadecimal) digit character into an integer. digitToInt :: Char -> Int digitToInt c | isDigit c = ord c - ord '0' | ord c >= ord 'A' && ord c <= ord 'F' = ord c - ord 'A' + 10 | ord c >= ord 'a' && ord c <= ord 'f' = ord c - ord 'a' + 10 | otherwise = error "Char.digitToInt: argument is not a digit" | isDigit c = ord c - ord '0' | ord c >= ord 'A' && ord c <= ord 'F' = ord c - ord 'A' + 10 | ord c >= ord 'a' && ord c <= ord 'f' = ord c - ord 'a' + 10 | otherwise = error "Char.digitToInt: argument is not a digit" --- Converts an integer into a (hexadecimal) digit character. intToDigit :: Int -> Char ... ...
 ... ... @@ -36,7 +36,8 @@ elemIndex x = findIndex (x ==) elemIndices :: Eq a => a -> [a] -> [Int] elemIndices x = findIndices (x ==) --- Returns the first element `e` of a list satisfying a predicate as `(Just e)`, --- Returns the first element `e` of a list satisfying a predicate --- as `(Just e)`, --- otherwise `Nothing` is returned. find :: (a -> Bool) -> [a] -> Maybe a find p = listToMaybe . filter p ... ... @@ -142,13 +143,13 @@ diagonal = concat . foldr diags [] --- Returns the list of all permutations of the argument. permutations :: [a] -> [[a]] permutations xs0 = xs0 : perms xs0 [] where where perms [] _ = [] perms (t:ts) is = foldr interleave (perms ts (t:is)) (permutations is) where interleave xs r = let (_, zs) = interleave' id xs r in zs interleave' _ [] r = (ts, r) interleave' f (y:ys) r = let (us, zs) = interleave' (f . (y:)) ys r in (y:us, f (t:y:us) : zs) in (y:us, f (t:y:us) : zs) --- Partitions a list into a pair of lists where the first list --- contains those elements that satisfy the predicate argument ... ... @@ -157,8 +158,9 @@ permutations xs0 = xs0 : perms xs0 [] --- Example: `(partition (<4) [8,1,5,2,4,3]) = ([1,2,3],[8,5,4])` partition :: (a -> Bool) -> [a] -> ([a],[a]) partition p xs = foldr select ([],[]) xs where select x (ts,fs) = if p x then (x:ts,fs) else (ts,x:fs) where select x (ts,fs) = if p x then (x:ts,fs) else (ts,x:fs) --- Splits the list argument into a list of lists of equal adjacent --- elements. ... ... @@ -184,10 +186,11 @@ splitOn :: Eq a => [a] -> [a] -> [[a]] splitOn [] _ = error "splitOn called with an empty pattern" splitOn [x] xs = split (x ==) xs splitOn sep@(_:_:_) xs = go xs where go [] = [[]] go l@(y:ys) | sep `isPrefixOf` l = [] : go (drop len l) | otherwise = let (zs:zss) = go ys in (y:zs):zss len = length sep where go [] = [[]] go l@(y:ys) | sep `isPrefixOf` l = [] : go (drop len l) | otherwise = let (zs:zss) = go ys in (y:zs):zss len = length sep --- Splits a list into components delimited by separators, --- where the predicate returns True for a separator element. ... ... @@ -197,7 +200,7 @@ splitOn sep@(_:_:_) xs = go xs --- > split (=='a') "aabbaca" == ["","","bb","c",""] --- > split (=='a') "" == [""] split :: (a -> Bool) -> [a] -> [[a]] split _ [] = [[]] split _ [] = [[]] split p (x:xs) | p x = [] : split p xs | otherwise = let (ys:yss) = split p xs in (x:ys):yss ... ... @@ -221,7 +224,7 @@ tails xxs@(_:xs) = xxs : tails xs --- @param ys - the old list --- @return the new list where the `p`. element is replaced by `x` replace :: a -> Int -> [a] -> [a] replace _ _ [] = [] replace _ _ [] = [] replace x p (y:ys) | p==0 = x:ys | otherwise = y:(replace x (p-1) ys) ... ... @@ -230,8 +233,8 @@ replace x p (y:ys) | p==0 = x:ys --- @param ys - a list --- @return `True` if `xs` is a prefix of `ys` isPrefixOf :: Eq a => [a] -> [a] -> Bool isPrefixOf [] _ = True isPrefixOf (_:_) [] = False isPrefixOf [] _ = True isPrefixOf (_:_) [] = False isPrefixOf (x:xs) (y:ys) = x==y && (isPrefixOf xs ys) --- Checks whether a list is a suffix of another. ... ... @@ -290,7 +293,7 @@ merge leq (x:xs) (y:ys) | leq x y = x : merge leq xs (y:ys) --- @param xs - a list --- @return a list where the element has been inserted insertBy :: (a -> a -> Bool) -> a -> [a] -> [a] insertBy _ x [] = [x] insertBy _ x [] = [x] insertBy le x (y:ys) = if le x y then x : y : ys else y : insertBy le x ys ... ... @@ -321,9 +324,10 @@ maximum xs@(_:_) = foldl1 max xs --- according to the given comparison function maximumBy :: (a -> a -> Ordering) -> [a] -> a maximumBy cmp xs@(_:_) = foldl1 maxBy xs where maxBy x y = case cmp x y of GT -> x _ -> y where maxBy x y = case cmp x y of GT -> x _ -> y --- Returns the minimum of a non-empty list. minimum :: Ord a => [a] -> a ... ... @@ -333,17 +337,18 @@ minimum xs@(_:_) = foldl1 min xs --- according to the given comparison function minimumBy :: (a -> a -> Ordering) -> [a] -> a minimumBy cmp xs@(_:_) = foldl1 minBy xs where minBy x y = case cmp x y of GT -> y _ -> x where minBy x y = case cmp x y of GT -> y _ -> x --- `scanl` is similar to `foldl`, but returns a list of successive --- reduced values from the left: --- scanl f z [x1, x2, ...] == [z, z `f` x1, (z `f` x1) `f` x2, ...] scanl :: (a -> b -> a) -> a -> [b] -> [a] scanl f q ls = q : (case ls of [] -> [] x:xs -> scanl f (f q x) xs) [] -> [] x:xs -> scanl f (f q x) xs) --- `scanl1` is a variant of `scanl` that has no starting value argument: --- scanl1 f [x1, x2, ...] == [x1, x1 `f` x2, ...] ... ...
 ... ... @@ -106,7 +106,7 @@ \$(CABAL_FILE): ../Makefile Makefile echo "Description: The standard libraries for KiCS2" >> \$@ echo "License: OtherLicense" >> \$@ echo "Author: The KiCS2 Team" >> \$@ echo "Maintainer: kics2@curry-language.org" >> \$@ echo "Maintainer: kics2@curry-lang.org" >> \$@ echo "Build-Type: Simple" >> \$@ echo "Cabal-Version: >= 1.9.2" >> \$@ echo "" >> \$@ ... ... @@ -127,7 +127,7 @@ \$(CABAL_TRACE_FILE): ../Makefile Makefile echo "Description: The tracing standard libraries for KiCS2" >> \$@ echo "License: OtherLicense" >> \$@ echo "Author: The KiCS2 Team" >> \$@ echo "Maintainer: kics2@curry-language.org" >> \$@ echo "Maintainer: kics2@curry-lang.org" >> \$@ echo "Build-Type: Simple" >> \$@ echo "Cabal-Version: >= 1.9.2" >> \$@ echo "" >> \$@ ... ...
 ... ... @@ -20,6 +20,7 @@ LIB_NAMES = \$(subst /,., \$(basename \$(LIB_CURRY))) LIB_DOCNAMES = \$(filter-out \$(DOCEXCLUDES), \$(LIB_NAMES)) # Generated files: LIB_FCY = \$(foreach lib, \$(LIB_CURRY:%.curry=.curry/%.fcy), \$(lib)) LIB_TFCY = \$(foreach lib, \$(LIB_CURRY:%.curry=.curry/%.tfcy),\$(lib)) LIB_ACY = \$(foreach lib, \$(LIB_CURRY:%.curry=.curry/%.acy), \$(lib)) LIB_PL = \$(foreach lib, \$(LIB_CURRY:%.curry=.curry/pakcs/%.pl), \$(lib)) LIB_HTML = \$(foreach lib, \$(LIB_CURRY:.curry=.html), \$(LIBDOCDIR)/\$(subst /,.,\$(lib))) ... ... @@ -66,6 +67,10 @@ cleanpl: .PHONY: fcy fcy: \$(LIB_FCY) # generate the type-annotated FlatCurry files of all libraries: .PHONY: tfcy tfcy: \$(LIB_TFCY) # generate the AbstractCurry files of all libraries: .PHONY: acy acy: \$(LIB_ACY) ... ... @@ -79,6 +84,10 @@ pl: .curry/pakcs/\$(ALLLIBS).pl \$(LIB_PL) .curry/%.fcy: %.curry "\$(CYMAKE)" --flat \$(CYMAKEPARAMS) \$(subst /,.,\$*) -D__PAKCS__=\$(shell printf '%d%02d' \$(MAJORVERSION) \$(MINORVERSION)) # generate type-annotated FlatCurry file in subdirectory .curry: .curry/%.tfcy: %.curry "\$(CYMAKE)" --typed-flat \$(CYMAKEPARAMS) \$(subst /,.,\$*) -D__PAKCS__=\$(shell printf '%d%02d' \$(MAJORVERSION) \$(MINORVERSION)) # generate all AbstractCurry files in subdirectory .curry: .curry/%.acy: %.curry "\$(CYMAKE)" --acy \$(CYMAKEPARAMS) \$(subst /,.,\$*) -D__PAKCS__=\$(shell printf '%d%02d' \$(MAJORVERSION) \$(MINORVERSION)) ... ...