Skip to content

Conversation

@stylewarning
Copy link
Member

@stylewarning stylewarning commented Sep 9, 2025

This is to scratch an itch of being able to print stuff, superseding trace and friends. It introduces two type classes:

  • ShowType :t with show-type-to to reify a string representation of :t
  • Show :t with show-to to reify a string representation of values of :t for debugging purposes

Both use a "callback-style" interface: provide an f :: (String -> Unit) to these procedures, and f will be called on the component strings. One can always build an actual, full string with show-as-string and show-inferred-type-as-string.

COALTON-USER> (coalton (show* 1 2 "hello" 4 #\Newline (Reveal (fn () 5))))
12hello4
#<FUNCTION-ENTRY :ARITY 1>

Other cool things:

COALTON-USER> (coalton (coalton-library/show:show-inferred-type-as-string
                        (Some (fn (x) (Cons (Complex x 0.0d0) Nil)))))
"(Optional (Arrow F64 (List (Complex F64))))"

COALTON-USER> (coalton (coalton-library/show:show-as-string
                        (coalton-library/lisparray:make 5 1.0d0)))
"(lisparray [1.0d0 1.0d0 1.0d0 1.0d0 1.0d0])"

COALTON-USER> (coalton (coalton-library/show:show-inferred-type-as-string
                        (coalton-library/lisparray:make 5 1.0d0)))
"(LispArray F64)"

COALTON-USER> (coalton (coalton-library/show:show-inferred-type-as-readable-string
                        (coalton-library/lisparray:make 5 1.0d0)))
"(COALTON-LIBRARY/LISPARRAY:LISPARRAY COALTON:F64)"

TODO:

  • Finish implementing ShowType and Show for the rest of the library types.
  • Decide on the naming of all of the classes and methods.

Future work:

  • Write a deriver for this.

Copy link
Collaborator

@YarinHeffes YarinHeffes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great 👍

Comment on lines +48 to +58
(inline)
(declare proxy-function-from (Proxy (:a -> :b) -> Proxy :a))
(define (proxy-function-from _)
"Get a `Proxy` representing the \"domain\" of a function type."
Proxy)

(inline)
(declare proxy-function-to (Proxy (:a -> :b) -> Proxy :b))
(define (proxy-function-to _)
"Get a `Proxy` representing the \"codomain\" of a function type."
Proxy)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's your opinion on using the following instead?

Suggested change
(inline)
(declare proxy-function-from (Proxy (:a -> :b) -> Proxy :a))
(define (proxy-function-from _)
"Get a `Proxy` representing the \"domain\" of a function type."
Proxy)
(inline)
(declare proxy-function-to (Proxy (:a -> :b) -> Proxy :b))
(define (proxy-function-to _)
"Get a `Proxy` representing the \"codomain\" of a function type."
Proxy)
(inline)
(declare proxy-left (Proxy (:T :a :b) -> Proxy :a))
(define (proxy-left _)
"Get a `Proxy` representing the \"domain\" of a relational type."
Proxy)
(inline)
(declare proxy-right (Proxy (:T :a :b) -> Proxy :b))
(define (proxy-right _)
"Get a `Proxy` representing the \"codomain\" of a relational type."
Proxy)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that because it doesn't make sense for types like Result or Either, but I think (?) that'll typecheck. What about proxy-function-arg and proxy-function-result? from/to also seem fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants