Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
clean-compiler-and-rts
compiler
Commits
63e1e7f3
Commit
63e1e7f3
authored
Sep 20, 2000
by
Martin Wierich
Browse files
new Bag type: :: Bag x = Pair (Bag x) (Bag x) | Single x | Empty
using this for accumulators is more elegant than using lists
parent
6402c61b
Changes
2
Hide whitespace changes
Inline
Side-by-side
frontend/utilities.dcl
View file @
63e1e7f3
...
...
@@ -115,3 +115,8 @@ iterateSt op st :== iterate_st op st
revAppend
::
![
a
]
![
a
]
->
[
a
]
// Reverse the list using the second argument as accumulator.
revMap
::
!(.
a
->
.
b
)
![.
a
]
!
u
:[.
b
]
->
u
:[.
b
]
::
Bag
x
=
Empty
|
Single
!
x
|
Pair
!(
Bag
x
)
!(
Bag
x
)
uniqueBagToList
::
!*(
Bag
x
)
->
[
x
]
// exploits reuse of unique nodes (if compiled with that option)
bagToList
::
!(
Bag
x
)
->
[
x
]
isEmptyBag
::
!(
Bag
x
)
->
Bool
frontend/utilities.icl
View file @
63e1e7f3
...
...
@@ -222,3 +222,33 @@ zip2Append [] [] tail
zip2Append [x : xs] [y : ys] tail
= [(x,y) : zip2Append xs ys tail]
*/
::
Bag
x
=
Empty
|
Single
!
x
|
Pair
!(
Bag
x
)
!(
Bag
x
)
uniqueBagToList
::
!*(
Bag
x
)
->
[
x
]
// exploits reuse of unique nodes (if compiled with that option)
uniqueBagToList
bag
=
accumulate_elements
bag
[]
where
accumulate_elements
::
!*(
Bag
x
)
[
x
]
->
[
x
]
accumulate_elements
Empty
accu
=
accu
accumulate_elements
(
Single
element
)
accu
=
[
element
:
accu
]
accumulate_elements
(
Pair
bag1
bag2
)
accu
=
accumulate_elements
bag1
(
accumulate_elements
bag2
accu
)
bagToList
::
!(
Bag
x
)
->
[
x
]
bagToList
bag
=
accumulate_elements
bag
[]
where
accumulate_elements
::
!(
Bag
x
)
[
x
]
->
[
x
]
accumulate_elements
Empty
accu
=
accu
accumulate_elements
(
Single
element
)
accu
=
[
element
:
accu
]
accumulate_elements
(
Pair
bag1
bag2
)
accu
=
accumulate_elements
bag1
(
accumulate_elements
bag2
accu
)
isEmptyBag
::
!(
Bag
x
)
->
Bool
isEmptyBag
Empty
=
True
isEmptyBag
_
=
False
Write
Preview
Supports
Markdown
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