diff --git a/src/std/float.no b/src/std/float.no index 2eab3e3..ddbfd39 100644 --- a/src/std/float.no +++ b/src/std/float.no @@ -1,31 +1,33 @@ pub type Float -pub let neg = fn(float): Float { - negFloat(float) -} +impl Num for Float { + neg = fn(self): Self { + negFloat(self) + } -pub let abs = fn(float): Float { - absFloat(float) -} + abs = fn(self): Self { + absFloat(self) + } -pub let add = fn(float, other: Float): Float { - addFloat(float, other) -} + add = fn(self, other: Self): Self { + addFloat(self, other) + } -pub let sub = fn(float, other: Float): Float { - subFloat(float, other) -} + sub = fn(self, other: Self): Self { + subFloat(self, other) + } -pub let mult = fn(float, other: Float): Float { - multFloat(float, other) -} + mult = fn(self, other: Self): Self { + multFloat(self, other) + } -pub let div = fn(float, other: Float): Float { - divFloat(float, other) -} + div = fn(self, other: Self): Self { + divFloat(self, other) + } -pub let exp = fn(float, other: Float): Float { - expFloat(float, other) + exp = fn(self, other: Self): Self { + expFloat(self, other) + } } impl Eq for Float { diff --git a/src/std/future/mod.no b/src/std/future/mod.no index f42be7c..1e52156 100644 --- a/src/std/future/mod.no +++ b/src/std/future/mod.no @@ -1,4 +1,6 @@ use std::ref::eqRef +use std::list::{ add } +use std::future::runtime::{ Runtime, runtime } pub type Future( f: fn(resolve: fn(result: T): Unit): Unit, @@ -16,8 +18,8 @@ pub type FutureState { impl Trace for FutureState {} -pub let new = fn(f: fn(resolve: fn(result: T): Unit): Unit): Self { - Future(f, [], FutureState::Created()) +pub let new = fn(f: fn(resolve: fn(result: T): Unit): Unit): Future { + Future(f, [], Created()) } pub let onResolve = fn(future: Future, f: fn(result: T): Unit): Unit { @@ -37,18 +39,18 @@ pub let onResolve = fn(future: Future, f: fn(result: T): Unit): Unit { // TODO: belongs to std::control::Functor pub let map = fn(future: Future, f: fn(value: T): U): Future { // TODO: use .await - Future::new(fn(resolve) { future.onResolve(fn(res) { resolve(f(res)) }) }) + new(fn(resolve) { future.onResolve(fn(res) { resolve(f(res)) }) }) } // TODO: belongs to std::control::Monad pub let flatMap = fn(future: Future, f: fn(value: T): Future): Future { // TODO: use .await - Future::new(fn(resolve) { + new(fn(resolve) { future.onResolve(fn (res) { f(res).onResolve(fn(inner) { resolve(inner) }) }) }) } -pub let spawn = fn(future: Future, runtime: Runtime): Self { +pub let spawn = fn(future: Future, runtime: Runtime): Future { runtime.spawn(future) } diff --git a/src/std/future/runtime.no b/src/std/future/runtime.no index 8b1fa43..41e6d87 100644 --- a/src/std/future/runtime.no +++ b/src/std/future/runtime.no @@ -1,3 +1,8 @@ +use std::future::{ self, FutureState, state, subscribers } +use std::list::{ add, count, popAt, clear, popFront } +use std::iter::{ Iter::position } +use std::ref::eqRef + pub type Runtime( // TODO: use std::time::Duration pollingRate: Int, @@ -5,23 +10,23 @@ pub type Runtime( pending: List>, ) -pub let runtime: Runtime = Runtime::new() +pub let runtime: Runtime = new() pub let new = fn(): Runtime { - Runtime::withPollingRate(10) + withPollingRate(10) } pub let withPollingRate = fn(pollingRate: Int): Runtime { - Runtime::Runtime(pollingRate, [], []) + Runtime(pollingRate, [], []) } pub let loop = fn(runtime): Unit { while runtime.queue.count() > 0 { let next = runtime.queue.popFront()! - next.state = FutureState::Pending() + next.state = future::Pending() runtime.pending.add(next) - let _ = {next.f}(fn(res) { - next.state = FutureState::Resolved(res) + let _ = {next.future::f}(fn(res) { + next.state = future::Resolved(res) for s in next.subscribers { s(res) } @@ -39,13 +44,13 @@ pub let loop = fn(runtime): Unit { pub let spawn = fn(runtime, future: Future): Future { runtime.queue.add(future) - future.state = FutureState::Queued() + future.state = future::Queued() future } // TODO: use std::time::Duration pub let delay = fn(delay: Int): Future { - Future::new(fn(resolve) { deferFor(fn() { resolve(unit) }, delay) }) + future::new(fn(resolve) { deferFor(fn() { resolve(unit) }, delay) }) } pub let defer = fn(f: fn(): Unit): Unit { diff --git a/src/std/int.no b/src/std/int.no index f4dd761..8121db2 100644 --- a/src/std/int.no +++ b/src/std/int.no @@ -1,31 +1,33 @@ pub type Int -pub let neg = fn(int): Int { - negInt(int) -} +impl Num for Int { + neg = fn(self): Self { + negInt(self) + } -pub let abs = fn(int): Int { - absInt(int) -} + abs = fn(self): Self { + absInt(self) + } -pub let add = fn(int, other: Int): Int { - addInt(int, other) -} + add = fn(self, other: Self): Self { + addInt(self, other) + } -pub let sub = fn(int, other: Int): Int { - subInt(int, other) -} + sub = fn(self, other: Self): Self { + subInt(self, other) + } -pub let mult = fn(int, other: Int): Int { - multInt(int, other) -} + mult = fn(self, other: Self): Self { + multInt(self, other) + } -pub let div = fn(int, other: Int): Int { - divInt(int, other) -} + div = fn(self, other: Self): Self { + divInt(self, other) + } -pub let exp = fn(int, other: Int): Int { - expInt(int, other) + exp = fn(self, other: Self): Self { + expInt(self, other) + } } pub let mod = fn(int, divisor: Int): Int { diff --git a/src/std/iter/peekable.no b/src/std/iter/peekable.no index 455a2dd..e0671da 100644 --- a/src/std/iter/peekable.no +++ b/src/std/iter/peekable.no @@ -1,3 +1,5 @@ +use std::iter::Iter::next + pub type PeekableIter( iter: Iter, peeked: Option> diff --git a/src/std/iter/repeat.no b/src/std/iter/repeat.no index 3dcc0fc..87b5853 100644 --- a/src/std/iter/repeat.no +++ b/src/std/iter/repeat.no @@ -16,6 +16,6 @@ impl Iter for RepeatIter { } pub let repeat = fn(item: T, count: Int): RepeatIter { - RepeatIter(range: RangeIter::RangeIter(0, count), item) + RepeatIter(range: RangeIter(0, count), item) } diff --git a/src/std/num.no b/src/std/num.no new file mode 100644 index 0000000..b87582a --- /dev/null +++ b/src/std/num.no @@ -0,0 +1,15 @@ +pub trait Num { + neg = fn(self): Self + + abs = fn(self): Self + + add = fn(self, other: Self): Self + + sub = fn(self, other: Self): Self + + mult = fn(self, other: Self): Self + + div = fn(self, other: Self): Self + + exp = fn(self, other: Self): Self +} diff --git a/src/std/prelude.no b/src/std/prelude.no index dd5f992..dedbbdc 100644 --- a/src/std/prelude.no +++ b/src/std/prelude.no @@ -5,11 +5,12 @@ pub use std::{ int::{ self, Int }, string::{ self, String }, char::{ self, Char }, - bool::{ self, Bool }, + bool::{ self, Bool, not }, + num::Num, eq::Eq, copy::{ Copy, copy }, ord::{ Ordering, Ord }, - iter::{ Iterable, Iter, Collector }, + iter::{ Iterable::{ self, iter }, Iter, Collector }, iter::range::range, iter::repeat::repeat, list::{ self, List }, diff --git a/src/std/string.no b/src/std/string.no index 9535fb9..61f1a76 100644 --- a/src/std/string.no +++ b/src/std/string.no @@ -3,7 +3,7 @@ use std::iter::MapAdapter pub type String // TODO: belongs to the Monoid trait -pub concat = fn(string: String, other: Self): String { +pub let concat = fn(string: String, other: String): String { concatString(string, other) }