h3rald / min

A small but practical concatenative programming language and shell
https://min-lang.org
MIT License
311 stars 23 forks source link

Expectation - TypeClasses #96

Closed ghost closed 3 years ago

ghost commented 3 years ago
(:str ( (str string?) (str length 0 ==) ) &&) 'char typeclass

( symbol expectChar
    (char :val ==> char :res)
    (val @res)
) ::

"a" expectChar puts

The above produces:

(!) src\base.min(60,14) [expectChar]: Incorrect values found on the stack:
- expected: char expectChar
- got:      string expectChar
    src\base.min(60,14) in symbol: expectChar

But that must worked as putting "a" on the terminal. I think, expectation seems not working right. When i give a string into symbol then the symbol infers it as string not char. Interesting. Why doesn't the constraint work?

I cannot control my expectations for typeclasses. My Question:

What is wrong at my code? Could you fix it?

h3rald commented 3 years ago

Erhm... (str length 0 ==) ← sure about that? 😉

If you change that to (str length 1 ==) everything works as expected 😄

ghost commented 3 years ago

Erhm... (str length 0 ==) ← sure about that? 😉

If you change that to (str length 1 ==) everything works as expected 😄

I ... I so laughed. 😄 Okey, i changed and it workwd. Thanks a lot !!!