coalton icon indicating copy to clipboard operation
coalton copied to clipboard

Proxy, Typeable, and TypeReps

Open aijony opened this issue 2 years ago • 2 comments

Facilitates the introspection of types.

  • (typeOf 1) => Integer
  • (typeRep (the (Proxy (Arrow Integer)) Proxy) => (-> Integer)

Every defined type is Typeable.

Depends on: #681

aijony avatar Jul 29 '22 00:07 aijony

Can typeRep, toProxy and typeOf be type-rep, to-proxy and type-of, please?

gefjon avatar Jul 29 '22 04:07 gefjon

I think it might be possible to do Typeable without poly kinds.

The api would be the same:

(define-type TypeRep)

(define-class (Typeable :a)
  (typeOf (Typeable :a => :a -> TypeRep)))

But the compiler generated instances would look a little different:

(define-type Unit)

(define-instance (Typeable Unit)) ;; compiler written

(define-type (Proxy :a) Proxy)

(define-instance (Typeable :a => Typeable (Proxy :a))) ;; compiler written

The instances without constraints are trivial:

(define-global-lexical |INSTANCE/TYPEABLE UNIT| coalton-impl/typechecker::*unit-type*)

Instances with constraints will need a little codegen magic:

(defun |INSTANCE/TYPEABLE PROXY :A| (#G403) 
  (coalton-impl/typechecker::%make-tapp
    coalton-library/typeable::*proxy-type* ;; not actually a special variable, needs to be pulled from env
    #G403)) ;; access secret parameter

eliaslfox avatar Jul 29 '22 22:07 eliaslfox

Closing as this would have required #681.

eliaslfox avatar Apr 05 '23 21:04 eliaslfox