diff --git a/src/enso.nim b/src/enso.nim index 37b6d12..0a50712 100644 --- a/src/enso.nim +++ b/src/enso.nim @@ -3,9 +3,8 @@ import std/[options, os, sugar] # Declarations type - Error* = enum OK, ERR - FileDesc* = enum STDIN, STDOUT, STDERR - IO*[T] = proc(): T + Error* = enum OK, ERR + IO*[T] = proc(): T func fileread*(file: string): IO[Option[string]] func filewrite*(data: string, file: string): IO[Error] @@ -14,7 +13,7 @@ func lift*(fn: proc(): void): IO[void] func lift*[T](fn: proc(): T): IO[T] func join*[T](io: IO[IO[T]]): IO[T] func map*[T, U](io: IO[T], fn: T -> U): IO[U] -func readstr*(stream: FileDesc): IO[string] +func readln*(fd: File): IO[string] func run*[T](io: IO[T]): T func strput*(str: string): IO[void] func to_IO*[T](val: T): IO[T] @@ -60,14 +59,8 @@ func join*[T](io: IO[IO[T]]): IO[T] = map(io, run) func map*[T, U](io: IO[T], fn: T -> U): IO[U] = proc(): U = fn(run(io)) -func readstr*(stream: FileDesc): IO[string] = - case stream: - of STDIN: - lift proc(): string = readLine(stdin) - of STDOUT: - lift proc(): string = readLine(stdout) - of STDERR: - lift proc(): string = readLine(stderr) +func readln*(fd: File): IO[string] = + proc(): string = readLine(fd) func run*[T](io: IO[T]): T = io() diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..cd08755 --- /dev/null +++ b/test.txt @@ -0,0 +1 @@ +Hello world! diff --git a/tests/test.nim b/tests/test.nim index 32dc026..d15f9cb 100644 --- a/tests/test.nim +++ b/tests/test.nim @@ -20,7 +20,7 @@ func main() = let get_filename: IO[string] = proc(): string = - let name: IO[string] = readstr(STDIN) + let name: IO[string] = readln(stdin) echo "Enter the file name:" name()