AshleyYakeley / Truth

Changes and Pinafore projects. Pull requests not accepted.
https://pinafore.info/
GNU General Public License v2.0
32 stars 0 forks source link

STDIO functions #163

Closed AshleyYakeley closed 1 year ago

AshleyYakeley commented 1 year ago
AshleyYakeley commented 1 year ago

Streams are for UNIX weenies. Let's do something more interesting.

AshleyYakeley commented 1 year ago
type Source;
stdin: Source;
read: Source -> (Maybe Text -> Action Unit) -> Action Unit;
linebuffer: (Maybe Text -> Action Unit) -> Action (Maybe Text -> Action Unit);
gather: Action ((Maybe Text -> Action Unit) *: Action Text);
type Sink;
stdout: Sink;
stderr: Sink;
write: Sink -> Maybe Text -> Action Unit;
writeln: Sink -> Text -> Action Unit;
AshleyYakeley commented 1 year ago

Parameterised:

type Source +a;
stdin: Source Text;
read: Source a -> (Maybe a -> Action Unit) -> Action Unit;
linebuffer: (Maybe Text -> Action Unit) -> Action (Maybe Text -> Action Unit);
gather: Action ((Maybe a -> Action Unit) *: Action a);
type Sink -a;
stdout: Sink Text;
stderr: Sink Text;
write: Sink a -> Maybe a -> Action Unit;
writeln: Sink Text -> Text -> Action Unit;
AshleyYakeley commented 1 year ago

Maybe:

write: Sink a -> a -> Action Unit;
writeEnd: Sink None -> Action Unit;
AshleyYakeley commented 1 year ago

Maybe:

datatype Sink -a of
    MkSink (Maybe a -> Action Unit);
end;
AshleyYakeley commented 1 year ago

Maybe:

data Source +a of
    MkSource (Sink a -> Action Unit);
end;
AshleyYakeley commented 1 year ago
concatSink: List (Sink a) -> Sink a;
sumSink: Sink a -> Sink b -> Sink (a +: b);
listSink: Sink a -> Sink (List a);
concatSource: List (Source a) -> Source a; # mix sources together
sumSource: Source a -> Source b -> Source (a +: b)
= fns sa sb => concatSource [mapSource Left sa, mapSource Right sb];
listSource: Source (List a) -> Source a;
AshleyYakeley commented 1 year ago

Done.