h3rald / min

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

Expect With Typeclasses #92

Closed ghost closed 3 years ago

ghost commented 3 years ago
(:str ( (str string?) (str length 1 ==) ) &&) 'char typeclass   ; I defined in 'stypes.min' file

"a" (*stypes/type:char) expect puts         ; <--ERROR

Error:

(!) src\base.min(7,30) [expect]: Incorrect values found on the stack:      
- expected: *stypes/type:char expect
- got:      string expect
    src\base.min(7,30) in symbol: expect
ghost commented 3 years ago

Could we declare using typeclass as validating at expect, type? keywords?

ghost commented 3 years ago

(Thinking 😃 ) ... I understand what happened: When we typing an value "abc" then it will be constructed as string. This rule isn't affected by special types. Okay. I must use a symbol that controls that it is proper for our own special types like char? or char-expect:

( symbol char-expect
  (char :value ==> char :result)
  (value @result)
) ::

"a" char-expect puts ; Screen: "a"
 1   char-expect puts ; Screen: <ERROR will be printed>