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

Specify struct type in struct fields #36

Open
vklquevs opened this issue Mar 29, 2018 · 2 comments
Open

Specify struct type in struct fields #36

vklquevs opened this issue Mar 29, 2018 · 2 comments

Comments

@vklquevs
Copy link

I tried to specify a struct name as a field type:

ketos=> (struct foo ((a string)))
foo
ketos=> (struct bar ((b foo)))
bar
ketos=> (new bar :b (new foo :a "fails"))
Traceback:

  In main, lambda
  In system function new

execution error: type error for field `b` of struct `bar`: expected foo; found struct: foo { a: "fails" }
ketos=> (struct baz ((b struct)))
baz
ketos=> (new baz :b (new foo :a "works"))
baz { b: foo { a: "works" } }

The error confused me for a while until I realized the type for all struct values is "struct". Could it allow you to specify a struct type for a field?

Also, the definition for bar was accepted, even though there is no such type foo - every attempt to create a bar will fail to typecheck!

@murarth
Copy link
Owner

murarth commented Mar 30, 2018

Yes, struct definitions are seriously half-assed. No doubt.

I've been kicking around different ideas for how to improve it, but I haven't yet arrived at a clear vision for a total re-design of the struct operator. Until I do, you can leave this issue open to remind me (and maybe to collect other ideas to improve struct definitions).

@NickGeek
Copy link

NickGeek commented Dec 5, 2020

Potentially a more ADT style approach could be used, like data in Haskell or enum in Rust?

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

3 participants