Skip to content

Commit

Permalink
Std: update scoping rules for trait fns
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanjermakov committed Nov 22, 2024
1 parent 1bf8245 commit 9e9ade9
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 37 deletions.
2 changes: 0 additions & 2 deletions src/std/copy.no
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub trait Copy {
copy = fn(self): Self
}

pub let copy = fn<T>(value: T): T
2 changes: 1 addition & 1 deletion src/std/future/runtime.no
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::future::{ self, FutureState, state, subscribers }
use std::list::{ add, count, popAt, clear, popFront }
use std::iter::{ Iter::position }
use std::iter::position
use std::ref::eqRef

pub type Runtime(
Expand Down
2 changes: 1 addition & 1 deletion src/std/iter/intersperseIter.no
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::iter::{ PeekableIter, PeekableAdapter }
use std::iter::peekable::PeekableIter

pub type IntersperseIter<T>(
iter: PeekableIter<T>,
Expand Down
26 changes: 12 additions & 14 deletions src/std/iter/mod.no
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
pub use std::iter::{
intersperseIter::{ IntersperseIter, IntersperseAdapter },
mapIter::{ MapIter, MapAdapter },
peekable::{ PeekableIter, PeekableAdapter },
takeWhile::{ TakeWhileIter, TakeWhileAdapter },
intersperseIter::intersperse,
mapIter::map,
peekable::{ peekable, peek },
takeWhile::takeWhile,
}

pub trait Iterable<T> {
Expand Down Expand Up @@ -32,31 +32,29 @@ pub trait Iter<T> {
return res
}

position = fn(self, f: fn(elem: T): Bool): Option<Int> {
let i = 0
find = fn(self, f: fn(elem: T): Bool): Option<T> {
for n in self {
match f(n) {
true { return Some(i) }
}
i = i + 1
}
None()
}

find = fn(self, f: fn(elem: T): Bool): Option<T> {
collect = fn<C: Collector<T>>(self): C {
fromIter<C>(self)
}

position = fn(self, f: fn(elem: T): Bool): Option<Int> {
let i = 0
for n in self {
match f(n) {
true { return Some(i) }
}
i = i + 1
}
None()
}

collect = fn<C: Collector<T>>(self): C {
// TODO
// C::fromIter(self)
todo()
}
}

impl <T> Iterable<T> for Iter<T> {
Expand Down
2 changes: 0 additions & 2 deletions src/std/iter/peekable.no
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::iter::Iter::next

pub type PeekableIter<T>(
iter: Iter<T>,
peeked: Option<Option<T>>
Expand Down
2 changes: 0 additions & 2 deletions src/std/list.no
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::iter::{ MapAdapter, IntersperseAdapter }

pub type List<T>

pub let at = fn<T>(list: List<T>, index: Int): Option<T> {
Expand Down
1 change: 1 addition & 0 deletions src/std/option.no
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub let unwrap = fn<T>(option: Option<T>): T {
}

impl <T> Unwrap<T> for Option<T> {
// TODO: use identity fn
bind = fn(self): Option<T> {
self
}
Expand Down
26 changes: 13 additions & 13 deletions src/std/prelude.no
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
pub use std::{
unit::{ Unit, unit },
never::Never,
float::{ self, Float },
int::{ self, Int },
string::{ self, String },
char::{ self, Char },
bool::{ self, Bool, not },
num::Num,
eq::Eq,
float::{ Float },
int::{ Int, mod },
string::{ String, concat },
char::{ Char },
bool::{ Bool, and, or, not },
num::{ Num, neg, abs, add, sub, mult, div, exp },
eq::{ Eq, eq, ne },
copy::{ Copy, copy },
ord::{ Ordering, Ord },
iter::{ Iterable::{ self, iter }, Iter, Collector },
ord::{ Ordering, Less, Equal, Greater, Ord, cmp, ge, le, gt, lt },
iter::{ self, Iterable, iter , Iter, next, count, last, fold, find, collect, Collector },
iter::range::range,
iter::repeat::repeat,
list::{ self, List },
panic::{ panic, todo },
unwrap::{ Unwrap },
io::{ self, println },
fmt::{ show::Show, trace::Trace },
option::{ self, Option, Some, None },
result::{ self, Result, Ok, Error },
io::{ println },
fmt::{ show::{ Show, show }, trace::{ Trace, trace } },
option::{ Option, Some, None, isSome, isNone },
result::{ Result, Ok, Error, isOk, isError, ok, error },
future::Future,
}
2 changes: 0 additions & 2 deletions src/std/string.no
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use std::iter::MapAdapter

pub type String

// TODO: belongs to the Monoid trait
Expand Down

0 comments on commit 9e9ade9

Please sign in to comment.