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
Tim Steenvoorden
cleanbase
Commits
7e493cb5
Commit
7e493cb5
authored
Mar 07, 2016
by
Tim Steenvoorden
Browse files
rename size to length in Control.Foldable (to match Haskell)
parent
452db724
Changes
2
Hide whitespace changes
Inline
Sidebyside
Sources/Control/Foldable.dcl
View file @
7e493cb5
...
...
@@ 30,7 +30,7 @@ defaultFoldl` :: (b a > b) b (t a) > b  Foldable t
/// # Special folds
null
::
(
t
a
)
>
Bool

Foldable
t
size
::
(
t
a
)
>
Nat

Foldable
t
length
::
(
t
a
)
>
Nat

Foldable
t
elem
::
a
(
t
a
)
>
Bool

Foldable
t
&
Eq
a
notElem
::
a
(
t
a
)
>
Bool

Foldable
t
&
Eq
a
find
::
(
a
>
Bool
)
(
t
a
)
>
Maybe
a

Foldable
t
...
...
Sources/Control/Foldable.icl
View file @
7e493cb5
...
...
@@ 4,7 +4,6 @@ import Data.Function
import
Data
.
Bool
import
Data
.
Nat
import
Data
.
Maybe
import
Data
.
List
import
Algebra
.
Order
...
...
@@ 58,11 +57,11 @@ defaultFoldl` f z0 l = foldr f` id l z0
null
::
(
t
a
)
>
Bool

Foldable
t
null
xs
=
foldr
(\_
_
>
False
)
True
xs
/// Returns the
size/
length of a finite structure as an `Nat`. The
/// Returns the length of a finite structure as an `Nat`. The
/// default implementation is optimized for structures that are similar to
/// conslists, because there is no general way to do better.
size
::
(
t
a
)
>
Nat

Foldable
t
size
xs
=
foldl
(\
c
_
>
c
+
(
nat
1
))
(
nat
0
)
xs
length
::
(
t
a
)
>
Nat

Foldable
t
length
xs
=
foldl
(\
c
_
>
c
+
(
nat
1
))
(
nat
0
)
xs
// Does the element occur in the structure?
elem
::
a
(
t
a
)
>
Bool

Foldable
t
&
Eq
a
...
...
@@ 76,7 +75,7 @@ notElem x y = not (elem x y)
// the leftmost element of the structure matching the predicate, or
// `Nothing` if there is no such element.
find
::
(
a
>
Bool
)
(
t
a
)
>
Maybe
a

Foldable
t
find
p
x
=
listToMaybe
(
foldMap
(\
x
>
if
(
p
x
)
[
x
]
[])
x
)
find
p
x
=
undefined
//
listToMaybe (foldMap (\x > if (p x) [x] []) x)
/// ## Ord
...
...
@@ 105,13 +104,13 @@ minimumBy p x = foldr1 min` x
/// The concatenation of all the elements of a container of lists.
/// This is a synonym for `fold`
concat
::
(
t
[
a
])
>
[
a
]

Foldable
t
concat
xs
=
fold
xs
concat
xs
=
undefined
//
fold xs
/// Map a function over all the elements of a container and concatenate
/// the resulting lists.
/// This is a synonym for `foldMap`
concatMap
::
(
a
>
[
b
])
(
t
a
)
>
[
b
]

Foldable
t
concatMap
f
xs
=
foldMap
f
xs
concatMap
f
xs
=
undefined
//
foldMap f xs
/// ## Monoids and Semirings
...
...
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