-
Notifications
You must be signed in to change notification settings - Fork 5
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
[WIP] Typeclasses all the way!!! #2
base: master
Are you sure you want to change the base?
Conversation
Thanks! The current design is indeed pretty bad. It started as a quick hack when I started working on a Open CASCADE backend (https://github.com/dzufferey/scadla-oce-backend/). The common CSG core is shared but other operations are completely different. Unfortunately, that part is not really documented yet. I did not know about the link you shared on f-bounds. After a quick glance that looks like a good solution but I have not yet had the time to read it in details. I'll try to read the article and look at you pull request in the coming two weeks. I expect to accept the pull request because it looks like a good solution to the current hack. But I still want to read the code and understand it. |
Thanks for the reply! In the last days, I didn't convince myself that this is the good way to solve this problem. I like this project, it gives tools to solve a problem, and give totally other kind of problems to solve :D BTW: I never learned shapeless, but for me, it seems like the problem that maybe shapeless could solve too. When I will have time I will try to experience with that too to solve the "too much implicits" problem. |
Sorry for taking time. I thought about this more. I think the typeclasses are parbably part of the solutions but not quite enough. Ideally, what is needed is something that behaves well w.r.t. subtyping like the type classes but a bit more flexible like union type. I'm thinking that the union type could describe the operations used within a solid. This would allow different backend to support arbitrary subset of the operations. Your intuition of looking at shapeless is good. I don't know shapeless either but it seems that it can tackle this. I need to look deeper into this. I started to look a bit more into what there is currently in terms of elements and backends.
At that point, JCSG supports a subset of OpenSCAD and Open CASCADE is quite different. Also there is the question of 2D over what. As far as I can tell, OpenSCAD is 2D with and underlying planar surface and OpenCASCADE, for some operations, can work with 2D manifold. At the moment, I trying to learn more about shapeless. |
I tried shapeless, and I failed with it. Out of the tutorial implementing some basic things this worked flawlessly:
The problem starts to appear when you try to migrate "dynamic" code like:
You cant move a I also tried to ask the community: https://users.scala-lang.org/t/set-of-implicits-automatically-or-more-implicit-implicits/5075 but not much help so far. (But at least you can check my repo :) ) I think union types will not work, or at least will not solve the core problem of why I get started with the whole refactoring idea. If the implementation you gave has a missing something (like heightmaps), you need to add that to the "union". I think the beauty of the typeclass solution would be that you can came up with anything and you can render it without the need to implement a renderer function for all language. Kind of inverse of control, you have a something, the renderer can render sth, and at compile time the language can tell you which renderer functions you need to write if you want to render your things. That would make the whole solution much easily extendable, and would give a lot of room for optimizations without killing the generalization and reusability. (For example we can have a centered cube, and we can center it by translations, or if the lang (for ex openscad) can render it natively, we can write an openscad specific renderer function for it which could be more optimal.) If we start to use union types I think we close ourselves to the same box as we have now with the match-cases. I'm still can't let this problem go, I try to bring in some programmers (in meetups and local chats), maybe sb has a good idea how I can create more implicit implicits :D |
Hi, Two days ago I was lucky to meet with some people involved in the Scala development (EPFL connections 😃 ). They old me that that dotty (Scala 3) is trying to tackle that issue and will provide native support for union types: https://dotty.epfl.ch/docs/reference/new-types/union-types.html I need to give that a try. |
I still didn't quite sure why union types will rescue as. I think union type will only help if we already know all the subtypes. So if I want to On the other hand, if I wrap the |
Hy!
First of all nice lib!
Second:
What I was not really liked here is the coupled solid-renderer code. When I tried to add new openScad capabilities, everything started to get messy.
So I started to refactor the code with Typeclasses, and bcs I reached a point when I see how it goes, I want to ask your opinion if its an improvement or a drawback.
The basic idea:
Instead of a big match-case in every renderer, we need to implement
Renderer[A]
classes. So we would know at compile time for example if JCSG could render aBeltMold.inner
or not.The pros:
first successful render
for reference).The cons:
+
operator)Basically the first 3 commits are the interesting ones.
The next steps if we move forward:
I would like to hear the authors voice before I move forward, or give up :D
I reached the point when I think that for the stuff I want to do, (and with the code I already written) I would be ok in a separate project too. But it would be nice if I could contribute to an existing thing and not reinvent a concurrent just bcs I was lazy to refactor :D
(Also this could be a good reading if you are not familiar with it: https://tpolecat.github.io/2015/04/29/f-bounds.html)