/* ----------------------------------------------------------------------------- Copyright 2019-2020 Kevin P. Barry Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ----------------------------------------------------------------------------- */ // Author: Kevin P. Barry [ta0kira@gmail.com] // TODO: Split this up, or otherwise organize it better. concrete Void { refines Formatted defines Equals defines LessThan @type void () -> (Void) } @value interface ReadCurrent<|#x> { readCurrent () -> (#x) } @value interface IterateForward<|#x> { forward () -> (#x) pastForwardEnd () -> (Bool) } @value interface IterateReverse<|#x> { reverse () -> (#x) pastReverseEnd () -> (Bool) } concrete ReadIterator<|#x> { refines ReadCurrent<#x> refines IterateForward> refines IterateReverse> @category fromReadPosition<#y> (ReadPosition<#y>) -> (ReadIterator<#y>) @category fromReadPositionAt<#y> (ReadPosition<#y>,Int) -> (ReadIterator<#y>) } @value interface Writer<#x|> { write (#x) -> () } @value interface BufferedWriter<#x|> { refines Writer<#x> flush () -> () } concrete LazyStream<#x> { @type new () -> (LazyStream<#x>) @value append (#x) -> (LazyStream<#x>) @value writeTo (BufferedWriter<#x>) -> () } concrete SimpleOutput { @type stdout () -> (BufferedWriter) @type stderr () -> (BufferedWriter) @type error () -> (BufferedWriter) } concrete SimpleInput { @type stdin () -> (BlockReader) } concrete Argv { refines ReadPosition @type global () -> (ReadPosition) } @value interface PersistentResource { freeResource () -> () } @value interface BlockReader<|#x> { readBlock (Int) -> (#x) pastEnd () -> (Bool) } @value interface BlockWriter<#x|> { writeBlock (#x) -> (Int) } concrete TextReader { @type fromBlockReader (BlockReader) -> (TextReader) @type readAll (BlockReader) -> (String) @value readNextLine () -> (String) @value pastEnd () -> (Bool) } concrete ErrorOr<|#x> { @category value<#x> (#x) -> (ErrorOr<#x>) @category error (Formatted) -> (ErrorOr) @value isError () -> (Bool) @value getValue () -> (#x) @value getError () -> (Formatted) @value convertError () -> (ErrorOr) }