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

[Tinkering] Object Oriented HTML Templating #5

Closed
wants to merge 14 commits into from

Conversation

complyue
Copy link
Collaborator

@complyue complyue commented Jun 5, 2024

This is based on #4, one major change is to have OO inheritance happen at user site instead of lib site. But "descendant object" has to recite all "methods" of super class (effect), maybe syntactic sugar can help with it, but I keep thinking other alternatives...

@complyue
Copy link
Collaborator Author

complyue commented Jun 5, 2024

given it's always explicitly passed, an evidence/handle of some named effect is essentially an object-reference under disguise? despite resume/ctl ability the methods can have.

fun body-begin-scripts(): (() -> <html-tree|e> ())
fun body-end-scripts(): (() -> <html-tree|e> ())

fun defaultpage(action: ev<html-layout<<pure|e>>> -> <pure|e> a) : <pure|e> a
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a Koka module ref bug here? it's not pub but can be used from front.kk with simple import.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually no bug here. If you don't specify a module name (module html/layout) at the top of the file, it's not really a separate module, more of just a source file, and everything is defaulted to pub.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice to know this trick, can I understand it like when you import a module which w/o its own module declaration, the result is like how #include work in C?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Essentially yes.

fun body-begin-scripts()
super.body-begin-scripts()
fun body-end-scripts() fn()
super.body-end-scripts()()
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the fn() and ()() looks really weird, but might simply bcoz we are demonstrating "settability" for object semantics.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also because we want to delay execution so that the html-tree effect gets called in the html-head / html-body, and not here (where there is no html-tree handler installed). We could change this code similarly to #3, in which case we end up with something like #6

@complyue
Copy link
Collaborator Author

complyue commented Jun 5, 2024

@TimWhiting , I don't know where to look at, but does Koka currently have some syntax support in defining a named handler, to automatically delegate methods to a specified evidence/handle on omission?

fun do(action : () -> e a) : e a
action()

value struct cnode
Copy link
Collaborator Author

@complyue complyue Jun 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Koka warns:

Type cnode requires 40 bytes which is rather large for a value type

does this mean value keyword will force the generated machine code pass that struct values via registers/stack ?

i wonder if string fields would also have its var-len payload packed altogether, i'm thinking about koka-lang/koka#543 , mini-heaps with var-len data seem to work performantly that way too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Koka ultimately leaves the registers / stack up to the C compiler. However, it does mean that the string struct will be embedded in the cnode struct instead of having a pointer to that value. However, it doesn't change whether the strings themselves are value / ref objects. Strings are currently represented by a length and then the pointer to the chars (not necessarily allocated next to the length field).

@TimWhiting
Copy link
Member

@TimWhiting , I don't know where to look at, but does Koka currently have some syntax support in defining a named handler, to automatically delegate methods to a specified evidence/handle on omission?

No, but it would be a good issue to raise on Koka's repo. Specifically to another named handler would be good I think.

fun set-body-content(c)
super.set-body-content(c)
fun set-page-title(t)
super.set-page-title(t)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the way you designed this we can probably get rid of the set-* methods. Which would make this somewhat nicer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, agree.

This was referenced Jun 5, 2024
@complyue
Copy link
Collaborator Author

complyue commented Jun 5, 2024

closing this in preference to #6

@complyue complyue closed this Jun 5, 2024
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

Successfully merging this pull request may close these issues.

None yet

2 participants