Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
clean-and-itasks
clean-platform
Commits
0ac185a6
Verified
Commit
0ac185a6
authored
Oct 25, 2017
by
Camil Staps
🚀
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More documentation
parent
0030a984
Pipeline
#8078
failed with stage
in 1 minute and 43 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
93 additions
and
22 deletions
+93
-22
src/libraries/OS-Independent/Data/Error.dcl
src/libraries/OS-Independent/Data/Error.dcl
+9
-0
src/libraries/OS-Independent/Data/Func.dcl
src/libraries/OS-Independent/Data/Func.dcl
+23
-0
src/libraries/OS-Independent/Data/Heap.dcl
src/libraries/OS-Independent/Data/Heap.dcl
+21
-0
src/libraries/OS-Independent/Data/Map.dcl
src/libraries/OS-Independent/Data/Map.dcl
+10
-6
src/libraries/OS-Independent/Data/Queue.dcl
src/libraries/OS-Independent/Data/Queue.dcl
+14
-12
src/libraries/OS-Independent/Data/Stack.dcl
src/libraries/OS-Independent/Data/Stack.dcl
+16
-4
No files found.
src/libraries/OS-Independent/Data/Error.dcl
View file @
0ac185a6
...
@@ -5,8 +5,17 @@ from Control.Monad import class Monad
...
@@ -5,8 +5,17 @@ from Control.Monad import class Monad
from
Control
.
Applicative
import
class
Applicative
from
Control
.
Applicative
import
class
Applicative
from
Data
.
Maybe
import
::
Maybe
from
Data
.
Maybe
import
::
Maybe
/**
* A type representing something that may have failed.
* @var The error type.
* @var The value type.
*/
::
MaybeError
a
b
=
Error
a
|
Ok
b
::
MaybeError
a
b
=
Error
a
|
Ok
b
/**
* Like {{`MaybeError`}} but with {{`String`}} as error type.
* @var The value type.
*/
::
MaybeErrorString
a
:==
MaybeError
String
a
::
MaybeErrorString
a
:==
MaybeError
String
a
instance
Functor
(
MaybeError
a
)
instance
Functor
(
MaybeError
a
)
...
...
src/libraries/OS-Independent/Data/Func.dcl
View file @
0ac185a6
...
@@ -13,8 +13,31 @@ definition module Data.Func
...
@@ -13,8 +13,31 @@ definition module Data.Func
*/
*/
app
f
:==
f
app
f
:==
f
/**
* Apply a state function to a list of values.
* See also {{`mapSt`}}.
*
* @param The function.
* @param The list of values.
* @param The initial state.
* @result The final state.
*/
seqSt
::
!(
a
.
st
->
.
st
)
![
a
]
!.
st
->
.
st
seqSt
::
!(
a
.
st
->
.
st
)
![
a
]
!.
st
->
.
st
/**
* Apply a state function to a list of values and return the results.
* See also {{`seqSt`}}.
*
* @param The function.
* @param The list of values.
* @param The initial state.
* @result The value results and the final state.
*/
mapSt
::
!(
a
.
st
->
(!
b
,!.
st
))
![
a
]
!.
st
->
(![
b
],!.
st
)
mapSt
::
!(
a
.
st
->
(!
b
,!.
st
))
![
a
]
!.
st
->
(![
b
],!.
st
)
/**
* The fixed point combinator, reducing `fix f` to `f (fix f)`.
*/
fix
::
(
a
->
a
)
->
a
fix
::
(
a
->
a
)
->
a
/**
/**
...
...
src/libraries/OS-Independent/Data/Heap.dcl
View file @
0ac185a6
...
@@ -84,18 +84,39 @@ partition :: (a -> Bool) (Heap a) -> (Heap a, Heap a)
...
@@ -84,18 +84,39 @@ partition :: (a -> Bool) (Heap a) -> (Heap a, Heap a)
split
::
a
(
Heap
a
)
->
(
Heap
a
,
Heap
a
,
Heap
a
)
split
::
a
(
Heap
a
)
->
(
Heap
a
,
Heap
a
,
Heap
a
)
/**
* @type Int (Heap a) -> Heap a
*/
take
:==
withList
o
'L'
.
take
take
:==
withList
o
'L'
.
take
/**
* @type Int (Heap a) -> Heap a
*/
drop
:==
withList
o
'L'
.
drop
drop
:==
withList
o
'L'
.
drop
/**
* @type Int (Heap a) -> (Heap a, Heap a)
*/
splitAt
:==
splitWithList
o
'L'
.
splitAt
splitAt
:==
splitWithList
o
'L'
.
splitAt
/**
* @type (a -> Bool) (Heap a) -> (Heap a, Heap a)
*/
break
:==
splitWithList
o
'L'
.
break
break
:==
splitWithList
o
'L'
.
break
/**
* @type (a -> Bool) (Heap a) -> (Heap a, Heap a)
*/
span
:==
splitWithList
o
'L'
.
span
span
:==
splitWithList
o
'L'
.
span
/**
* @type (a -> Bool) (Heap a) -> Heap a
*/
takeWhile
:==
withList
o
'L'
.
takeWhile
takeWhile
:==
withList
o
'L'
.
takeWhile
/**
* @type (a -> Bool) (Heap a) -> Heap a
*/
dropWhile
:==
withList
o
'L'
.
dropWhile
dropWhile
:==
withList
o
'L'
.
dropWhile
nub
::
(
Heap
a
)
->
Heap
a
nub
::
(
Heap
a
)
->
Heap
a
...
...
src/libraries/OS-Independent/Data/Map.dcl
View file @
0ac185a6
...
@@ -107,9 +107,17 @@ del :: !k !(Map k a) -> Map k a | < k
...
@@ -107,9 +107,17 @@ del :: !k !(Map k a) -> Map k a | < k
delU
::
!
a
!.(
Map
a
b
)
->
u
:(!
v
:(
Maybe
b
),
!
Map
a
b
)
|
==
a
&
<
a
,
[
u
<=
v
]
// !k !w:(Map k u:v) -> x:(Maybe u:v, !y:(Map k u:v)) | == k & < k, [ w y <= u, x <= y, w <= y]
delU
::
!
a
!.(
Map
a
b
)
->
u
:(!
v
:(
Maybe
b
),
!
Map
a
b
)
|
==
a
&
<
a
,
[
u
<=
v
]
// !k !w:(Map k u:v) -> x:(Maybe u:v, !y:(Map k u:v)) | == k & < k, [ w y <= u, x <= y, w <= y]
foldrWithKey
::
!(
k
v
u
:
a
->
u
:
a
)
!
u
:
a
!(
Map
k
v
)
->
u
:
a
foldrWithKey
::
!(
k
v
u
:
a
->
u
:
a
)
!
u
:
a
!(
Map
k
v
)
->
u
:
a
//foldrNoKey :: !(v u:a -> u:a) !u:a !(Map k v) -> u:a
foldlWithKey
::
!(
u
:
a
k
v
->
u
:
a
)
!
u
:
a
!(
Map
k
v
)
->
u
:
a
foldlWithKey
::
!(
u
:
a
k
v
->
u
:
a
)
!
u
:
a
!(
Map
k
v
)
->
u
:
a
//foldlNoKey :: !(a -> b -> a) !a !(Map c b) -> a
/**
* @type (v a -> a) a (Map k v) -> a
*/
foldrNoKey
f
x
m
:==
foldrWithKey
(\_
v
acc
->
f
v
acc
)
x
m
/**
* @type (a v -> a) a (Map k v) -> a
*/
foldlNoKey
f
x
m
:==
foldlWithKey
(\
acc
_
v
->
f
acc
v
)
x
m
/**
/**
* Filter elements in a Map.
* Filter elements in a Map.
...
@@ -218,10 +226,6 @@ mergeWithKey :: !(k a b -> Maybe c) !((Map k a) -> Map k c) !((Map k b) -> Map k
...
@@ -218,10 +226,6 @@ mergeWithKey :: !(k a b -> Maybe c) !((Map k a) -> Map k c) !((Map k b) -> Map k
foldlStrict
::
!(
a
b
->
a
)
!
a
![
b
]
->
a
foldlStrict
::
!(
a
b
->
a
)
!
a
![
b
]
->
a
foldrNoKey
f
x
m
:==
foldrWithKey
(\_
v
acc
->
f
v
acc
)
x
m
foldlNoKey
f
x
m
:==
foldlWithKey
(\
acc
_
v
->
f
acc
v
)
x
m
/**
/**
* Removes the values at given key positions. The mapping itself can be spine unique.
* Removes the values at given key positions. The mapping itself can be spine unique.
*
*
...
...
src/libraries/OS-Independent/Data/Queue.dcl
View file @
0ac185a6
definition
module
Data
.
Queue
definition
module
Data
.
Queue
/**
/**
* This module provides a straightforward FIFO queue.
* This module provides a straightforward FIFO queue.
* It is implemented using two list based on Chris Okasaki's example in Purely Functional Data Structures.
* It is implemented using two list based on Chris Okasaki's example in Purely
*/
* Functional Data Structures.
*/
from
Data
.
Maybe
import
::
Maybe
from
Data
.
Maybe
import
::
Maybe
from
StdOverloaded
import
class
length
from
StdOverloaded
import
class
length
...
@@ -10,14 +12,14 @@ from StdOverloaded import class length
...
@@ -10,14 +12,14 @@ from StdOverloaded import class length
::
Queue
a
=
Queue
[
a
]
[
a
]
::
Queue
a
=
Queue
[
a
]
[
a
]
/**
/**
* Create an empty queue
* Create an empty queue
*/
*/
newQueue
::
Queue
a
newQueue
::
Queue
a
/**
/**
* Test if the queue is empty
* Test if the queue is empty
*/
* @type (Queue a) -> Bool
//empty :: Queue a -> Bool
*/
empty
q
:==
case
q
of
empty
q
:==
case
q
of
Queue
[]
[]
->
True
Queue
[]
[]
->
True
_
->
False
_
->
False
...
@@ -25,11 +27,11 @@ empty q :== case q of
...
@@ -25,11 +27,11 @@ empty q :== case q of
instance
length
Queue
instance
length
Queue
/**
/**
* Add an element to the queue
* Add an element to the queue
*/
*/
enqueue
::
a
(
Queue
a
)
->
Queue
a
enqueue
::
a
(
Queue
a
)
->
Queue
a
/**
/**
* Take an element from the queue (if the queue is not empty)
* Take an element from the queue (if the queue is not empty)
*/
*/
dequeue
::
(
Queue
a
)
->
(!
Maybe
a
,!
Queue
a
)
dequeue
::
(
Queue
a
)
->
(!
Maybe
a
,!
Queue
a
)
src/libraries/OS-Independent/Data/Stack.dcl
View file @
0ac185a6
...
@@ -4,20 +4,32 @@ from StdOverloaded import class length
...
@@ -4,20 +4,32 @@ from StdOverloaded import class length
::
Stack
a
=
Stack
[
a
]
::
Stack
a
=
Stack
[
a
]
/**
* Create a new, empty Stack.
*/
newStack
::
Stack
a
newStack
::
Stack
a
/**
* Check whether a Stack is empty.
* @type (Stack a) -> Bool
*/
empty
a
:==
case
a
of
empty
a
:==
case
a
of
Stack
[]
->
True
Stack
[]
->
True
_
->
False
_
->
False
instance
length
Stack
instance
length
Stack
// Add element to the Stack
/**
* Add an element to the Stack.
*/
push
::
a
(
Stack
a
)
->
Stack
a
push
::
a
(
Stack
a
)
->
Stack
a
// Remove element from the Stack and return it if the Stack is not empty
/**
* Remove element from the Stack and return it if the Stack is not empty.
*/
pop
::
(
Stack
a
)
->
(
Maybe
a
,
Stack
a
)
pop
::
(
Stack
a
)
->
(
Maybe
a
,
Stack
a
)
// Peek the top of the Stack
/**
* Peek the top of the Stack.
*/
peek
::
(
Stack
a
)
->
Maybe
a
peek
::
(
Stack
a
)
->
Maybe
a
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