dictu-lang / Dictu

Dictu is a high-level dynamically typed, multi-paradigm, interpreted programming language.
https://dictu-lang.com
MIT License
267 stars 53 forks source link

[FEATURE] Type Hints (Discussion) #670

Open Jason2605 opened 1 year ago

Jason2605 commented 1 year ago

Is there an existing issue for this?

Is your feature request related to a problem?

Building out a fully blown type system is probably a little above my pay grade, however, what we can potentially do is add type hints into dictu. These would function exactly the same as Python's type hints (which are essentially glorified comments) but will allow us to use external tools to check for things, or even just provide a little more clarity to the developer about a type even if there isn't actually any checking taking place

Describe the solution you'd like

Something along the lines of:

const myString: string = "hello!!";
const myString -> string = "hello!!";

def lengthGreatherThanFive(myString: string): boolean {
    return myString.len() > 5;
}

def lengthGreatherThanFive(myString -> string) -> boolean {
    return myString.len() > 5;
}

// Maybe a mix?
def lengthGreatherThanFive(myString: string) -> boolean {
    return myString.len() > 5;
}

Describe alternatives you've considered

No response

Additional context

No response

briandowns commented 1 year ago

Definitely in favor of the : option.

RevengerWizard commented 1 year ago

Python's way of handling type hints is especially tricky and weird, given that it treats everything after the : or -> as a normal language expression that doesn't produce any bytecode, essentially a comment.

It's also interesting how Typescript, but usually Javascript, handle type hints inside separate .d.ts files which basically only contain the relevant hints to functions, classes and attributes.

Jason2605 commented 1 year ago

Python's way of handling type hints is especially tricky and weird, given that it treats everything after the : or -> as a normal language expression that doesn't produce any bytecode, essentially a comment.

I was thinking something similar, except unlike python, it doesn't even need to be a valid identifier (will massively simplify things for us).

Yeah the d.ts files allow you to have type information about some public API written in JS, I think for us, we'd probably just have it mixed into the actual source file (rather than a separate dedicated file) - again will be simpler to implement