Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Type system #14

Open
holgerl opened this issue Jun 27, 2018 · 1 comment
Open

Type system #14

holgerl opened this issue Jun 27, 2018 · 1 comment

Comments

@holgerl
Copy link
Owner

holgerl commented Jun 27, 2018

A type system would enable better error messages and a range of other benefits.

It could be done within the current syntax:

@ var foo type number = 42
@ var bar type number = (2.5 + 40.3)

@ var value type string = "lorem ipsum" // perhaps call the type "text"?

@ var isDone type boolean = true // perhaps call the type "truth"?

// type of list is defined as the type of the last evaluated value, so that it might be a list of code to be evaluated
@ var myList type number = 
    1
    2
    3

@ var baz type MyService = (@.MyService) // Not currently possible in hilvl to store services in variables?

// Comparing types:
@ typeof baz == MyService


// Types of arguments and return values:

@ var MyService := // The type when not specifying any type is the value itself, so the type is MyService
    @ var myAction type string : // function from number to string
        @ var myVariable type number = (42 + (@ . argument type number)) // Argument usage is statically checked for type
        @.myVariable as string // The return value is statically checked for type
        
@ var myValue type string = (MyService myAction 1)


// Types when doing higher order programming:

@ var MyService := 
    @ var myAction type number :
        @ set foo = 42 // Variable in inner scope
        @ var myFunction : (@.argument type number) // argument is a list of code with last value number
        @ myFunction // Invoking the argument as an action
        
@ var bar = 
    MyService myAction 
        @ set foo = 50
        @.foo + 2


// Alternative syntax?
@ type number name foo = 42
@holgerl
Copy link
Owner Author

holgerl commented Oct 5, 2021

Alternatively, values can be used directly to express types:

(Here I am using name instead of var)

@ name myFunction type (0 , 0) :
    @ name foo type number = 3
    @ . myValue + (@ . argument)

@ name MyService := 
    @ name myAction type (0 , "") :
        @ var foo = 40
        @ . foo + (@ . argument) as string

@ name myStr type "" = "Hello"
@ name isItSo type true = false
@ name myStuff type (@ . MyService) = (@ . MyService)

Since type true is a little awkward. There could be some built in variables like this:

@ name Boolean = true
@ name Text = ""
@ name Number = 0

Then they are used like this:

@ name myStr type Text = "Hello"
@ name isItSo type Boolean = false
@ name foo type Number = 123

The number service already has an action as that takes string as as argument. This is really a kind of type, so it should be changed t use values as types:

42 as Number

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant