Skip to content

Commit

Permalink
Revert "Add effects to argument functions in stdlib, fixes #130"
Browse files Browse the repository at this point in the history
This reverts commit 92a548c.
  • Loading branch information
daanx committed Jun 17, 2021
1 parent a803fd0 commit d79a17f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
20 changes: 10 additions & 10 deletions lib/std/core.kk
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ fun filter( xs : list<a>, pred : a -> e bool ) : e list<a> {

// Remove those elements of a list that satisfy the given predicate `pred`.
// For example: `remove([1,2,3],odd?) == [2]`
fun remove( xs : list<a>, pred : a -> e bool ) : e list<a> {
fun remove( xs : list<a>, pred : a -> bool ) : list<a> {
xs.filter( fn(x) { !pred(x) } )
}

Expand Down Expand Up @@ -619,20 +619,20 @@ fun filter-map( xs : list<a>, pred : a -> e maybe<b> ) : e list<b> {
}

// Find the first element satisfying some predicate
fun find( xs : list<a>, pred : a -> e bool ) : e maybe<a> {
fun find( xs : list<a>, pred : a -> bool ) : maybe<a> {
xs.foreach-while fn(x) {
if (pred(x)) then Just(x) else Nothing
}
}

// Find the first element satisfying some predicate and return it.
fun find-maybe( xs : list<a>, pred : a -> e maybe<b> ) : e maybe<b>
fun find-maybe( xs : list<a>, pred : a -> maybe<b> ) : maybe<b>
{
xs.foreach-while(pred)
}

// Lookup the first element satisfying some predicate
fun lookup( xs : list<(a,b)>, pred : a -> e bool ) : e maybe<b>
fun lookup( xs : list<(a,b)>, pred : a -> bool ) : maybe<b>
{
xs.foreach-while fn(kv) {
if (pred(kv.fst)) then Just(kv.snd) else Nothing
Expand All @@ -658,7 +658,7 @@ fun list( m : maybe<a> ) : list<a>
}
}

private fun index-of-acc( xs : list<a>, pred : a -> e bool, idx : int ) : e int
private fun index-of-acc( xs : list<a>, pred : a -> bool, idx : int ) : int
{
match(xs) {
Nil -> 0 - 1
Expand All @@ -667,7 +667,7 @@ private fun index-of-acc( xs : list<a>, pred : a -> e bool, idx : int ) : e int
}

// Returns the index of the first element where `pred` holds, or `-1` if no such element exists.
fun index-of( xs : list<a>, pred : a -> e bool ) : e int
fun index-of( xs : list<a>, pred : a -> bool ) : int
{
index-of-acc( xs, pred, 0 )
}
Expand Down Expand Up @@ -1237,7 +1237,7 @@ fun maybe( i : int ) : maybe<int> {
if (i==0) then Nothing else Just(i)
}

fun fold-int( start : int, end : int, init : a, f : (int,a) -> e a ) : e a {
fun fold-int( start : int, end : int, init : a, f : (int,a) -> a ) : a {
if (start >= end) then return init
val x = f(start,init)
fold-int(unsafe-decreasing(start.inc), end, x, f)
Expand Down Expand Up @@ -1934,11 +1934,11 @@ fun head-char( s : string ) : maybe<char> {
//}

// Count the number of times a predicate is true for each character in a string
fun count( s : string, pred : (char) -> e bool ) : e int
fun count( s : string, pred : (char) -> bool ) : int
{
var cnt := 0
s.foreach fn(c) {
if (mask<local>(fn() { pred(c) })) then cnt := cnt+1
if (pred(c)) then cnt := cnt+1
}
cnt
}
Expand Down Expand Up @@ -2316,7 +2316,7 @@ fun show( xs : list<bool> ) : string {
show-list(xs,show)
}

fun show-tuple( x : (a,b), showfst : a -> e string, showsnd : b -> e string ) : e string {
fun show-tuple( x : (a,b), showfst : a -> string, showsnd : b -> string ) : string {
"(" ++ x.fst.showfst ++ "," ++ x.snd.showsnd ++ ")"
}

Expand Down
4 changes: 2 additions & 2 deletions test/cgen/wrong/assign1.kk.out
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ test/cgen/wrong/assign1.kk(6, 5): error: no function count is defined that match
inferred type: (counter<_h>, _a, ...) -> ...
candidates : count: forall<h> (counter : counter<h>) -> ref<h,int>
count: (s : string, pattern : string) -> int
count: (s : string, pred : (char) -> bool) -> int
count: (slice : sslice) -> int
count: (s : string) -> int
count: forall<e> (s : string, pred : (char) -> e bool) -> e int
count: (s : string) -> int

0 comments on commit d79a17f

Please sign in to comment.