enso.nim: Shaving off code

This commit is contained in:
buckwheat
2025-12-26 22:36:14 -08:00
parent e263a216d6
commit 297f23163f
3 changed files with 7 additions and 13 deletions

View File

@ -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()

1
test.txt Normal file
View File

@ -0,0 +1 @@
Hello world!

View File

@ -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()