Elsa icon indicating copy to clipboard operation
Elsa copied to clipboard

Add extensions for built-in predicates "always returning true" if corresponding argument is passed

Open Fuco1 opened this issue 7 years ago • 1 comments

So that (stringp "foo") or (integerp 1) are flagged as always true. and (stringp :keyword) as always false.

Fuco1 avatar Aug 18 '18 21:08 Fuco1

This can be made much more general with something like "multiple type signatures". I can set signature of stirngp to Mixed -> Bool and then add additional conditional signatures such as

String -> T
Mixed \ String -> Nil
Mixed -> Bool (this is the general one, always last because it's the broadest.  It's automatic)

The first to match will determine the "run-time" return type. This way it will be really fast to add type logic to functions and it can apply beyond predicates, for example -list from dash has logic "if list, return list, if atom, return it wrapped in a list", so the type would be:

[a] -> [a]
a -> [a]
Mixed -> List (automatic, but this should never match in practice)

Fuco1 avatar Aug 19 '18 18:08 Fuco1