-
Notifications
You must be signed in to change notification settings - Fork 79
Open
Labels
codegenCode generation matters (Coalton -> Lisp)Code generation matters (Coalton -> Lisp)enhancementNew feature or requestNew feature or requestperformance
Description
Sometimes we write code like
(repr :native foo)
(define-type Foo)
and Foo
naturally has an algebraic structure, but it's just opaque to Coalton. For example, consider
(repr :native (cl:unsigned-byte 32))
(define-type RGBA)
which holds an RGBA value in an 8-bit quadruplet. We would want to write code like
(match c
((RGBA r g b a) ...))
The goal of this task is to allow one to define the above.
If we want to go the 90% of the way there, we should allow arbitrary discriminated unions:
(repr :native (cl:or cl:single-float (cl:unsigned-byte 32)))
(define-type Color)
(define (f c)
(match c
((RGBA r g b a) ...)
((Grayscale p) ...)))
If we want to go the full mile, we should allow discrimination based off of a property of the value, not just its type:
(repr :native (cl:unsigned-byte 64))
(define-type Color)
;; RGB: first byte is #x00
;; Gray: first byte is #x01
;; HSL: first byte is #x02
;; etc.
(define (f c)
(match c
((RGB r g b) ...)
((Grayscale g) ...)
((HSL h s l) ...)))
Metadata
Metadata
Assignees
Labels
codegenCode generation matters (Coalton -> Lisp)Code generation matters (Coalton -> Lisp)enhancementNew feature or requestNew feature or requestperformance