sanctuary-js / sanctuary

:see_no_evil: Refuge from unsafe JavaScript
https://sanctuary.js.org
MIT License
3.03k stars 94 forks source link

Reflection / runtime type introspection #507

Open futpib opened 6 years ago

futpib commented 6 years ago

I think the function signature (as in S.even.toString()) should be accessible programmatically as a first-class thing (not a string), maybe behind a new option of $.create.

davidchambers commented 6 years ago

Are you imagining something like the following?

> S.even.types.length
2

> S.even.types[0] === $.Integer
true

> S.even.types[1] === $.Boolean
true
futpib commented 6 years ago

Yes, or maybe via S.type.

futpib commented 6 years ago

Actually, I can't imagine an f.types-like API that could expose type constraints, so it must be more elaborate.

Maybe a way to get arguments that were passed to def will do?

davidchambers commented 6 years ago

How about this?

f.name :: String
f.constraints :: StrMap (Array TypeClass)
f.types :: Array Type
futpib commented 6 years ago

Looks good.

It seems that if this gets implemented, type classes could then check method signatures (at the moment they only seem to check if methods exist). Is this desirable?

davidchambers commented 6 years ago

I don't think type classes such as Z.Functor should depend on Sanctuary-specific properties. sanctuary-type-classes is intended to interoperate with the wider Fantasy Land ecosystem.

This issue really belongs in the sanctuary-def issue tracker. Would you mind opening a new issue there, @futpib?