Type Classes and Generics #83
Replies: 4 comments 5 replies
-
@h3rald Good idea to solve it. We should make a try. After that, we could see what goes on. I am too excited 😋
Ah yes, the above code includes generic usement . Lexicalness may be a problem again(heh🤦 ). Because our generic types should be able to be controlled in operator body. However this can be useful i think. Am i right? |
Beta Was this translation helpful? Give feedback.
-
Yep. Actually... erhm, I actually already implemented type classes in the next branch. It turns out that making them symbols made everything much easier than expected: Next, generics, yes 😊 regarding generics usage in body... mmmmm that could actually be difficult, because t actually doesn't really exist as a symbol. In my previous example I was simply checking the type of one of the values instead. Also the generic declaration would actually be a little different than the one you used here... check the previous example... I was thinking of using a quotation instead of the type symbol... I will think about it. The problem with your example is that I would have to check for quotations first and then remove them, and then check the signature. Not sure. Other ideas? |
Beta Was this translation helpful? Give feedback.
-
At the future, i think there will be all doings in Min. I declare it as Min-phase. Now we are at Nim-phase. But your doings shifts the current phase to Min-phase. After that, there will be only adaptions will made in Nim. Other things will be on Min. However i think you don't desire to make everything within Min. Because i read the passage:
There is going to be a mind-branching and way-branching |
Beta Was this translation helpful? Give feedback.
-
Implemented both type classes and generic support in v0.29.0 😊🎉👍 |
Beta Was this translation helpful? Give feedback.
-
I am continuing here the discussion on generics and type classes that we started here, to keep it a bit more organized from the 1.0.0 discussion :)
So, to recap...
Generics
The idea is to provide a way to define generics by using a quotation within a signature, like this:
Type Classes
Originally I called them "type definitions" but I think type classes is more appropriate.
The idea is to extend min to add a new
typeclass
operator that would allow you to define a new type class specifying a quotation and a string-like value, like this:Concerning @baykus871's comment about lexical scoping... I understand what you mean, but this is not as easy as I thought: lexical scoping is implemented for symbols, but... I was thinking of keeping type classes out of the symbol table, like in another dictionary, and do not use lexical scoping to keep things simple.
However, if we don't have lexically-scoped type classes, then:
...which actually makes things more complicated! So let's see what happens if type classes are symbols. The only that there could be is conflict with existing symbols that to completely different things... BUT this could be solved by having the
typeclass
operator return a special symbol, for example a symbol prepended withtype:
. At present, you CANNOT create user symbols containing:
, so there's no possibility of conflict with ordinary symbols, and we get all the benefits of symbols (lexical scoping, sealing, etc.) for free! 👍So, to go back to our previous type class definition, it would basically define a lexically-scoped symbol called
type:natural
. If you call it directly, you basically execute the associated quotation, BUT when used within a signature quotation without thetype:
prefix, it would be used for validating a value, so you could write.The signature quotation is already special: essentially it contains symbols that are not actually evaluated, and the definitions are not really definitions (hence you can use
:result
to capture a quotation, not=result
) -- I am adding more magic here, but this is the tidiest (and simplest) way to manage this that I can think of!Beta Was this translation helpful? Give feedback.
All reactions