home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / MacHaskell 2.2 / ast / type-structs.scm < prev    next >
Encoding:
Text File  |  1994-09-27  |  4.1 KB  |  168 lines  |  [TEXT/CCL2]

  1. ;;;  File: ast/type-structs   Author: John
  2.  
  3. ;;; This contains AST structures for the type-related declarations,
  4. ;;; including `data', `class', `instance', and `type' decls.  Basic type
  5. ;;; syntax is also defined here.
  6.  
  7. ;;; Structures declared here:
  8. ;;;  type  type-var  type-con  context  signature  synonym-decl
  9. ;;;  data-decl  class-decl  instance-decl
  10.  
  11.  
  12. ;;; <type>  -> <atype>
  13. ;;;         -> <type> -> <type>                              ***
  14. ;;;         -> <tycon> <atype> ... <atype>                   tycon
  15. ;;;
  16. ;;; <atype> -> <tyvar>                                       tyvar
  17. ;;;         -> <tycon>                                       tycon
  18. ;;;         -> ()                                            ***
  19. ;;;         -> ( <type> )                                    grouping syntax
  20. ;;;         -> ( <type> , ... , <type>)                      ***
  21. ;;;         -> [ <type> ]                                    ***
  22. ;;; *** Special <tycon> cases
  23.  
  24. ;;; Type with no context - either a tyvar or a constructor
  25. (define-struct type
  26.   (include ast-node))
  27.  
  28. (define-struct tyvar
  29.   (include type)
  30.   (predicate tyvar?)
  31.   (slots
  32.    (name (type symbol))))
  33.  
  34. (define-struct tycon
  35.   (include type)
  36.   (predicate tycon?)
  37.   (slots
  38.    (name (type symbol))
  39.    (def (type def))
  40.    (args (type (list type)))))
  41.  
  42. ;;; <signature> -> [<context> =>] <type>
  43. ;;;
  44. ;;; <context> -> <class>
  45. ;;;           -> (<class> , ... , <class>)
  46.  
  47. ;;; A single class, variable pair
  48.  
  49. (define-struct context
  50.   (include ast-node)
  51.   (slots
  52.    (class (type class-ref))
  53.    (tyvar (type symbol))))
  54.  
  55. ;;; Type + context
  56. (define-struct signature
  57.   (include type)
  58.   (slots
  59.    (context (type (list context)))
  60.    (type (type type))))
  61.  
  62.  
  63. ;;; Major type declarations.  Note: no explicit structures for <simple>
  64. ;;; or <inst> are needed - these are just special cases of type.
  65.  
  66. ;;; <synonym-decl> -> type <simple> = <type>
  67. ;;;
  68. ;;; <simple> -> <tycon> <tyvar> ... <tyvar>
  69.  
  70. (define-struct synonym-decl
  71.   (include ast-node)
  72.   (slots
  73.    (simple (type type))
  74.    (body (type type))))
  75.  
  76.  
  77. ;;; <aldata-decl> -> data [<context> => ] <simple> = <constrs> 
  78. ;;;                    [deriving <tycls> | ( <tycls> , ... <tycls>) ]
  79. ;;;
  80. ;;; <constrs>     -> <constr> | ... | <constr>
  81. ;;;
  82.  
  83. (define-struct data-decl
  84.   (include ast-node)
  85.   (slots
  86.    (context (type (list context)))
  87.    (simple (type type))
  88.    (constrs (type (list constr)))  
  89.    (deriving (type (list class-ref)))
  90.    (annotations (type (list annotation-value)))))
  91.  
  92. ;;; <constr>      -> <con> <atype> ... <atype>
  93. ;;;               -> <type> <conop> <type>
  94.  
  95. (define-struct constr
  96.   (include ast-node)
  97.   (slots
  98.    (constructor (type con-ref))  ; this con-ref has an infix? flag.
  99.    (types (type (list (tuple type (list annotation-value)))))))
  100.  
  101.  
  102. ;;; <class-decl> -> class [<context> => ] <class> [where { <cbody> [;] } ]
  103. ;;;
  104. ;;; <cbody> -> [<csigns> ; ] [ <valdefs> ]
  105. ;;;
  106. ;;; <csigns> -> <signdecl> ; ... ; <signdecl>
  107.  
  108. (define-struct class-decl
  109.   (include ast-node)
  110.   (slots
  111.    (class (type class-ref))
  112.    (super-classes (type (list context)))
  113.    (class-var (type symbol))              ; name of type var for this class in decls
  114.    (decls (type (list decl)))))           ; <cbody>
  115.  
  116.  
  117. ;;; <instance-decl> -> instance [<context> =>] <tycls> <inst>
  118. ;;;                      [where { <valdefs> [;] } ]
  119. ;;;
  120. ;;; <inst> -> <tycon>
  121. ;;;        -> ( <tycon> <tyvar> ... <tyvar> )
  122. ;;;        -> ( <tyvar> , ... , <tyvar>)
  123. ;;;        -> ()
  124. ;;;        -> [ <tyvar> ]
  125. ;;;        -> ( <tyvar> -> <tyvar>)
  126. ;;;
  127.  
  128. (define-struct instance-decl
  129.   (include ast-node)
  130.   (slots
  131.    ;; <context>
  132.    (context (type (list context)))
  133.    ;; <tycls>
  134.    (class (type class-ref))
  135.    ;;
  136.    (simple (type type))
  137.    ;; <valdefs>
  138.    (decls (type (list valdef)))
  139.    ))
  140.  
  141.  
  142.  
  143. ;;; <default-decl> -> default <type>
  144. ;;;                -> default ( <type> , ... , <type> )
  145.  
  146. (define-struct default-decl
  147.   (include ast-node)
  148.   (slots
  149.    (types (type (list type)))))
  150.  
  151.  
  152. ;;; <tycls> -> <aconid>
  153.  
  154. (define-struct class-ref
  155.   (include ast-node)
  156.   (slots
  157.    (name (type symbol))
  158.    (class (type def))))
  159.  
  160.  
  161. (define-struct deriving-decl
  162.   (include ast-node)
  163.   (slots
  164.    (constraints (type (list context)))
  165.    (simple (type type))
  166.    (inst-decls (type (list instance-decl)))
  167.    ))
  168.