Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Fredrik Wieczerkowski
curry-libs
Commits
f5b6dd94
Commit
f5b6dd94
authored
Nov 08, 2019
by
Kai-Oliver Prott
Browse files
Merge remote-tracking branch 'origin/master' into version3
parent
4f063fa5
Changes
5
Hide whitespace changes
Inline
Side-by-side
Data/Char.curry
View file @
f5b6dd94
...
...
@@ -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
...
...
Data/List.curry
View file @
f5b6dd94
...
...
@@ -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, ...]
...
...
Makefile_kics2
View file @
f5b6dd94
...
...
@@ -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-lang
uage
.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-lang
uage
.org" >> $@
echo "Maintainer: kics2@curry-lang.org"
>> $@
echo "Build-Type: Simple" >> $@
echo "Cabal-Version: >= 1.9.2" >> $@
echo "" >> $@
...
...
Makefile_pakcs
View file @
f5b6dd94
...
...
@@ -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))
...
...
System/IO/Unsafe.curry
View file @
f5b6dd94
...
...
@@ -120,7 +120,7 @@ prim_showAnyQTerm external
--- containing a pair of the data term and the remaining unparsed string.
readsAnyUnqualifiedTerm :: [String] -> String -> [(_,String)]
readsAnyUnqualifiedTerm [] _ =
readsAnyUnqualifiedTerm []
_ =
error "ReadShowTerm.readsAnyUnqualifiedTerm: list of module prefixes is empty"
readsAnyUnqualifiedTerm (prefix:prefixes) s =
readsAnyUnqualifiedTermWithPrefixes (prefix:prefixes) s
...
...
@@ -135,20 +135,24 @@ prim_readsAnyUnqualifiedTerm external
--- Transforms a string containing a term in standard prefix notation
--- without module qualifiers into the corresponding data term.
--- The string might contain logical variable encodings produced by showAnyTerm.
--- The string might contain logical variable encodings produced by
--- `showAnyTerm`.
readAnyUnqualifiedTerm :: [String] -> String -> _
readAnyUnqualifiedTerm prefixes s = case result of
[(term,tail)]
-> if all isSpace tail then term
else error ("Unsafe.readAnyUnqualifiedTerm: no parse, unmatched string after term: "++tail)
-> if all isSpace tail
then term
else error ("Unsafe.readAnyUnqualifiedTerm: no parse, " ++
"unmatched string after term: " ++ tail)
[] -> error "Unsafe.readAnyUnqualifiedTerm: no parse"
_ -> error "Unsafe.readAnyUnqualifiedTerm: ambiguous parse"
where result = readsAnyUnqualifiedTerm prefixes s
--- Transforms a string containing a term in standard prefix notation
--- with qualified constructor names into the corresponding data term.
--- The string might contain logical variable encodings produced by showAnyQTerm.
--- The string might contain logical variable encodings produced by
--- `showAnyQTerm`.
--- In case of a successful parse, the result is a one element list
--- containing a pair of the data term and the remaining unparsed string.
...
...
@@ -160,25 +164,29 @@ prim_readsAnyQTerm external
--- Transforms a string containing a term in standard prefix notation
--- with qualified constructor names into the corresponding data term.
--- The string might contain logical variable encodings produced by showAnyQTerm.
--- The string might contain logical variable encodings produced by
--- `showAnyQTerm`.
readAnyQTerm :: String -> _
readAnyQTerm s = case result of
[(term,tail)] -> if all isSpace tail then term
else error "Unsafe.readAnyQTerm: no parse"
[] -> error "Unsafe.readAnyQTerm: no parse"
_ -> error "Unsafe.readAnyQTerm: ambiguous parse"
[(term,tail)] -> if all isSpace tail
then term
else error "Unsafe.readAnyQTerm: no parse"
[] -> error "Unsafe.readAnyQTerm: no parse"
_ -> error "Unsafe.readAnyQTerm: ambiguous parse"
where result = readsAnyQTerm s
--- Transforms any expression (even not in normal form) into a string representation
--- Transforms any expression (even not in normal form)
--- into a string representation
--- in standard prefix notation without module qualifiers.
--- The result depends on the evaluation and binding status of
--- logic variables so that it should be used with care!
showAnyExpression :: _ -> String
showAnyExpression external
--- Transforms any expression (even not in normal form) into a string representation
--- Transforms any expression (even not in normal form)
--- into a string representation
--- in standard prefix notation with module qualifiers.
--- The result depends on the evaluation and binding status of
--- logic variables so that it should be used with care!
...
...
@@ -206,9 +214,10 @@ prim_readsAnyQExpression external
readAnyQExpression :: String -> _
readAnyQExpression s = case result of
[(term,tail)] -> if all isSpace tail then term
else error "Unsafe.readAnyQExpression: no parse"
[] -> error "Unsafe.readAnyQExpression: no parse"
_ -> error "Unsafe.readAnyQExpression: ambiguous parse"
[(term,tail)] -> if all isSpace tail
then term
else error "Unsafe.readAnyQExpression: no parse"
[] -> error "Unsafe.readAnyQExpression: no parse"
_ -> error "Unsafe.readAnyQExpression: ambiguous parse"
where result = readsAnyQExpression s
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment