selfish-lang / selfish

Implementation of Selfish Shell Language
MIT License
7 stars 0 forks source link

Type System and Semantics #6

Open SchrodingerZhu opened 3 years ago

SchrodingerZhu commented 3 years ago

I think we can mimic Python, where almost everything is as objects; including library, string, etc; but I would like to keep basic numbers primitive.

In this issue, we need to resolve how to handle the coercion properly. To begin with, we may need to consider one of the most obvious problem:

Now, our expression syntax allow something like:

cat test.txt | grep meow | fn (x) { return length (split $x.stdout); } | some-command again

That is the pipeline can mix functions and command. Is it possible to let command operation return an object and then, for example use coercion to handle the above behavior?

also cc @ICEYSELF @ice1000 @outloudvi for suggestions

ice1000 commented 3 years ago

I have a slightly impolite question: why not put all of our efforts to Aya? By that we could have a very powerful dependent (and in the future, univalent) type system, and the selfish team could focus on the runtime.

ice1000 commented 3 years ago

I suggest coercion to be implicitly resolved Rust-styled From or Into trait. coerce term will coerce term to the expected type inferred from the context, and the coercion function will be resolved from the trait implementations. This assumes the language to have the trait construct, but I don't think it's that hard to add, considering the simplicity of the type system.

chuigda commented 3 years ago

In effect, an "external executable" provided by runtime environment can be treated:

Fn(input: Stream) -> (Stream, i32)

It should be trivial to implement things like ToString, FromString and WriteToStream for most types. But ReadFromStream don't think so. We must think carefully here.

chuigda commented 3 years ago

I have a slightly impolite question: why not put all of our efforts to Aya? By that we could have a very powerful dependent (and in the future, univalent) type system, and the selfish team could focus on the runtime.

I have a slightly impolite and cruel answer: nobody wants a dependent shell.