-
Notifications
You must be signed in to change notification settings - Fork 9
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
Typed def and DIM #62
Comments
After considerable recent though, I think the first of the two options, or rather something like it, is possible. In fact, if my thinking is correct, we don't need any kind of "type registry" at all. The normal process of function definition is more than sufficient. We create What it actually is, is a function declaration. The (dim str-idx (number? string?) -> string?) Would expand into something like: (define str-idx-chk (fun n1 s1)
(if (not (and (number? n1)
(string? s1)))
(error "bad argument")
(let [result (apply fun n1 s1)]
(if (not (string? result))
(error "bad return value")
result)))) Then our custom Typing so far has been optional, and in that regard, it is not a problem if there is no check function defined, but it does mean one could inadvertently typo the The big question is is this possible in a system with hygienic macros. That I do not actually know yet. If there is not some macro wizardry to do what is outlined, then another solution will have to be found. |
If this macrofuckery is not actually possible, I think the simplest proposal then is to add additional syntax to |
As discussed in the Racketfest 2019 presentation, I would like to consider adding predicate typing to function and variable declarations.
This would necessitate changes in three places:
def
,def fn
, and possiblylet
. Syntax support would need to be added to these forms, and additional semantics to support type checking of references both at creation and function application.One proposed solution that remains in the spirit of the BASIC roots of Heresy is the
DIM
keyword, which is used for array declarations in 8-bit BASICs, but later in many dialects for type predefinitions. A possible syntax would look like this:This has the advantage of not conflicting with existing
def
syntax, but has the disadvantage of potentially requiring some pretty tricky code rewriting magic, or even actually just requiring a type registry of some kind. Investigation of the methods in Typed Racket and Hackett may be instructive here.I see two possible solutions off hand:
dim
is a declaration form that binds a name to a type registry of some kind, basically a separate namespace of names to their type predicates, and then we modify the default#%app
further to check the values of a function application against the stored types before calling the function, while plaindef
's macro is modified to check the value about to be assigned.dim
must live on the line above a def, and actually rewrites the code below it somehow to inject the necessary code for type checking. This seems like how at least Typed Racket does it.The text was updated successfully, but these errors were encountered: