;;;;
;;;; 137.stk         -- Implementation of SRFI-137
;;;;
;;;; Copyright © 2020-2022 Erick Gallesio - I3S-CNRS/Polytech Nice-Sophia <eg@unice.fr>
;;;;
;;;;
;;;; This program is free software; you can redistribute it and/or modify
;;;; it under the terms of the GNU General Public License as published by
;;;; the Free Software Foundation; either version 2 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;;; GNU General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU General Public License
;;;; along with this program; if not, write to the Free Software
;;;; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
;;;; USA.
;;;;
;;;;           Author: Erick Gallesio [eg@unice.fr]
;;;;    Creation date: 11-Dec-2020 11:17
;;;;

(define-module srfi/137

  (export make-type)
  (define (make-type payload)
    (define (%make-type parent payload)
      (let ((type (make-struct-type payload parent '(instance-payload))))
        (values
         ;; type-accessor
         (lambda () payload)
         ;; constructor
         (lambda (payload) (make-struct type payload))
         ;; predicate
         (lambda (x) (and (struct? x)  (struct-is-a? x type)))
         ;; accessor
         (lambda (x) (if (and (struct? x)  (struct-is-a? x type))
                    (struct-ref x 'instance-payload)))
         ;; make-subtype
         (lambda (type-payload)
           (%make-type type type-payload)))))

    (%make-type #f payload)))

(provide "srfi/137")
