Closed ghost closed 3 years ago
Ohhh nice idea! It would be cool to define your own type definitions, for example with a quotation containing the checks to perform. This would be similar to Haskell's typeclasses I guess.
Is that what you are after? Maybe something like this:
(:n ((n int?) (n 0 >)) &&) 'natural typedef
so that you could write:
(
symbol natural-sum
(natural :n natural :m == natural :result)
(n m + @result)
) ::
It could be a nice feature indeed!
Yes, you true. Special types are really need for Min. And your natural
definition could be my definition probably. I think as you about natural definition and special type definition. You must be quick, i'm impatient at this time. I'm waiting you with my tea 🍵
You can add the feature until i am drinking my tea (i say you're very fast.) 😀
Haha not that fast! 🤣
I am developing my OSS projects in my free time, so that basically means a bit during weekends and at night when my daughter wakes up for feeding -- and that coding is done mostly by ssh'ing into my MacBook from my iPhone!
But yes, I'll try to implement it soon. It is doable, it's a matter of exposing some way to define constraints (basically via a quotation) and wiring them up with the operator and expect symbols. It can be done. Not sure how much performance overhead all these checks will add though... but that's another problem 😊
@h3rald
Hey h3rald! How can we use special types as constraints? Can you give an example please? I am preparing an example for you, for an opened issue. But this will be a future-included example so i must know how can i use constraints in a operator symbol definition.
Another que.: If we use constraints then Must we delete them via delete
symbol??
Sure, here:
; The following defines a special type:natural symbol
(:n ((n integer?) (n 0 >)) &&) 'natural typeclass
; type: prefixed symbols (which can only be created with the typeclass operator)
; can be used as types inside a signature quotation, without the type: prefix
(
symbol natural-sum
(natural :n natural :m ==> natural :result)
(n m + @result)
) ::
Hopefully I will find some time to document all this properly soon!
And well.. they are symbols, like any other... so you can keep them in the scope or delete them, up to you.
@h3rald
(:n ( (n integer?) (n 0 >) ) && ) 'natural typeclass
( symbol natural-sum
(natural :n natural :m ==> natural :result)
(n m + @result)
) ::
; But now i don't use the natural symbol.
; Because i use it for constrainting.
; This is a scrap at the moment:
'type:natural delete
I think this would be better than before:
( symbol natural-sum
(
((:n ( (n integer?) (n 0 >) ) && ) 'natural typeclass) :n
natural :m ==> natural :result
)
(n m + @result)
) ::
Noooo it has to exist ins the same scope as the operator(s) that use it for the constraint to work! If you delete it and you then use natural
in a signature, you will get an error saying invalid type!
The idea is that you probably want to reuse it... those could be general constraints as well, like natural.
Noooo it has to exist for the constraint to work! If you delete it and you then use
natural
in a signature, you will get an error saying invalid type!
Some types only declared for some symbols because of their specialities. When we delete it at the end of operator definition, then we are blocking ambiguity of calling it mistakenly.
I think this would be better than before:
( symbol natural-sum ( ((:n ( (n integer?) (n 0 >) ) && ) 'natural typeclass) :n natural :m ==> natural :result ) (n m + @result) ) ::
Isn't this good enough? We're extending constraint application(current: general constraints as you say) via special constraints.
Parameters section(quotation) of operator signature should have a typeface. That makes parameters section could have its own types too. ---> Am i false again????? 😫
Well, let's put it in this way:
typeclass
symbol lets you create special type:
prefixed symbols that you wouldn't otherwise be able to create (:
is not allowed in user symbols)What you are showing in the last example doesn't work right now, but it will hopefully work when I implement generics... 😊👍
What you are showing in the last example doesn't work right now, but it will hopefully work when I implement generics... 😊👍
No wait, I am getting confused now... generics should be simpler, more more like this:
(string|num|quot :t) :a
Not full quotations... I think 🤔
What you are showing in the last example doesn't work right now.
I gave a example from FUTURE-USAGE of Min with implementing your ideas IN.
You REALLY don't understand??? Is there anybody hearing my voice??? AAAAAAAAAA..!!!!
I'm I'm very tired of this topic. Do it as you thought. We say our solutions for the topic to each other. I am dropping talking for the topic. You are the author and you can improve Min lang. I don't want to be a block on your road. You must go on. 👍 👍 👍 OKAY??
Added support for type classes in v0.29.0
Now, there are some native types (
int
float
string
...) . However sometimes these aren't types what we needed. For examplenatural
type. It accepts only natural numbers not negative numbers.How can be adding special types in Min? How can apply our constraints within operator definition?