adam@1732: (* Copyright (c) 2008-2010, 2012, Adam Chlipala
adamc@2:  * All rights reserved.
adamc@2:  *
adamc@2:  * Redistribution and use in source and binary forms, with or without
adamc@2:  * modification, are permitted provided that the following conditions are met:
adamc@2:  *
adamc@2:  * - Redistributions of source code must retain the above copyright notice,
adamc@2:  *   this list of conditions and the following disclaimer.
adamc@2:  * - Redistributions in binary form must reproduce the above copyright notice,
adamc@2:  *   this list of conditions and the following disclaimer in the documentation
adamc@2:  *   and/or other materials provided with the distribution.
adamc@2:  * - The names of contributors may not be used to endorse or promote products
adamc@2:  *   derived from this software without specific prior written permission.
adamc@2:  *
adamc@2:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
adamc@2:  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
adamc@2:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
adamc@2:  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
adamc@2:  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
adamc@2:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
adamc@2:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
adamc@2:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
adamc@2:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
adamc@2:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
adamc@2:  * POSSIBILITY OF SUCH DAMAGE.
adamc@2:  *)
adamc@2: 
adamc@2: signature ELAB_UTIL = sig
adamc@2: 
adamc@198: val classifyDatatype : (string * int * 'a option) list -> Elab.datatype_kind
adamc@188: 
adam@1303: val mliftConInCon : (int -> Elab.con -> Elab.con) ref
adam@1303: 
adamc@2: structure Kind : sig
adamc@623:     val mapfoldB : {kind : ('context, Elab.kind', 'state, 'abort) Search.mapfolderB,
adamc@623:                     bind : 'context * string -> 'context}
adamc@623:                    -> ('context, Elab.kind, 'state, 'abort) Search.mapfolderB
adamc@6:     val mapfold : (Elab.kind', 'state, 'abort) Search.mapfolder
adamc@2:                   -> (Elab.kind, 'state, 'abort) Search.mapfolder
adamc@2:     val exists : (Elab.kind' -> bool) -> Elab.kind -> bool
adamc@623:     val mapB : {kind : 'context -> Elab.kind' -> Elab.kind',
adamc@623:                 bind : 'context * string -> 'context}
adamc@623:                -> 'context -> (Elab.kind -> Elab.kind)
adamc@2: end
adamc@2: 
adamc@6: structure Con : sig
adamc@11:     datatype binder =
adamc@623:              RelK of string
adamc@623:            | RelC of string * Elab.kind
adamc@792:            | NamedC of string * int * Elab.kind * Elab.con option
adamc@11: 
adamc@623:     val mapfoldB : {kind : ('context, Elab.kind', 'state, 'abort) Search.mapfolderB,
adamc@11:                     con : ('context, Elab.con', 'state, 'abort) Search.mapfolderB,
adamc@11:                     bind : 'context * binder -> 'context}
adamc@11:                    -> ('context, Elab.con, 'state, 'abort) Search.mapfolderB
adamc@6:     val mapfold : {kind : (Elab.kind', 'state, 'abort) Search.mapfolder,
adamc@10:                    con : (Elab.con', 'state, 'abort) Search.mapfolder}
adamc@6:                   -> (Elab.con, 'state, 'abort) Search.mapfolder
adamc@11: 
adamc@623:     val mapB : {kind : 'context -> Elab.kind' -> Elab.kind',
adamc@11:                 con : 'context -> Elab.con' -> Elab.con',
adamc@11:                 bind : 'context * binder -> 'context}
adamc@11:                -> 'context -> (Elab.con -> Elab.con)
adamc@34:     val map : {kind : Elab.kind' -> Elab.kind',
adamc@34:                con : Elab.con' -> Elab.con'}
adamc@34:               -> Elab.con -> Elab.con
adam@1639:     val appB : {kind : 'context -> Elab.kind' -> unit,
adam@1639:                 con : 'context -> Elab.con' -> unit,
adam@1639:                 bind : 'context * binder -> 'context}
adam@1639:                -> 'context -> (Elab.con -> unit)
adam@1639:     val app : {kind : Elab.kind' -> unit,
adam@1639:                con : Elab.con' -> unit}
adam@1639:               -> Elab.con -> unit
adamc@711:     val existsB : {kind : 'context * Elab.kind' -> bool,
adamc@711:                   con : 'context * Elab.con' -> bool,
adamc@711:                    bind : 'context * binder -> 'context}
adamc@711:                   -> 'context -> Elab.con -> bool
adamc@6:     val exists : {kind : Elab.kind' -> bool,
adamc@6:                   con : Elab.con' -> bool} -> Elab.con -> bool
adamc@448: 
adamc@623:     val foldB : {kind : 'context * Elab.kind' * 'state -> 'state,
adamc@448:                  con : 'context * Elab.con' * 'state -> 'state,
adamc@448:                  bind : 'context * binder -> 'context}
adamc@448:                 -> 'context -> 'state -> Elab.con -> 'state
adamc@839:     val fold : {kind : Elab.kind' * 'state -> 'state,
adamc@839:                  con : Elab.con' * 'state -> 'state}
adamc@839:                 -> 'state -> Elab.con -> 'state
adamc@6: end
adamc@6: 
adamc@10: structure Exp : sig
adamc@11:     datatype binder =
adamc@623:              RelK of string
adamc@623:            | RelC of string * Elab.kind
adamc@792:            | NamedC of string * int * Elab.kind * Elab.con option
adamc@11:            | RelE of string * Elab.con
adamc@11:            | NamedE of string * Elab.con
adamc@11: 
adamc@623:     val mapfoldB : {kind : ('context, Elab.kind', 'state, 'abort) Search.mapfolderB,
adamc@11:                     con : ('context, Elab.con', 'state, 'abort) Search.mapfolderB,
adamc@11:                     exp : ('context, Elab.exp', 'state, 'abort) Search.mapfolderB,
adamc@11:                     bind : 'context * binder -> 'context}
adamc@11:                    -> ('context, Elab.exp, 'state, 'abort) Search.mapfolderB
adamc@10:     val mapfold : {kind : (Elab.kind', 'state, 'abort) Search.mapfolder,
adamc@10:                    con : (Elab.con', 'state, 'abort) Search.mapfolder,
adamc@10:                    exp : (Elab.exp', 'state, 'abort) Search.mapfolder}
adamc@10:                   -> (Elab.exp, 'state, 'abort) Search.mapfolder
adamc@623:     val mapB : {kind : 'context -> Elab.kind' -> Elab.kind',
adamc@211:                 con : 'context -> Elab.con' -> Elab.con',
adamc@211:                 exp : 'context -> Elab.exp' -> Elab.exp',
adamc@211:                 bind : 'context * binder -> 'context}
adamc@211:                -> 'context -> (Elab.exp -> Elab.exp)
adamc@10:     val exists : {kind : Elab.kind' -> bool,
adamc@10:                   con : Elab.con' -> bool,
adamc@10:                   exp : Elab.exp' -> bool} -> Elab.exp -> bool
adam@1795:     val existsB : {kind : 'context * Elab.kind' -> bool,
adam@1795:                    con : 'context * Elab.con' -> bool,
adam@1795:                    exp : 'context * Elab.exp' -> bool,
adam@1795:                    bind : 'context * binder -> 'context}
adam@1795:                   -> 'context -> Elab.exp -> bool
adamc@448: 
adamc@623:     val foldB : {kind : 'context * Elab.kind' * 'state -> 'state,
adamc@448:                  con : 'context * Elab.con' * 'state -> 'state,
adamc@448:                  exp : 'context * Elab.exp' * 'state -> 'state,
adamc@448:                  bind : 'context * binder -> 'context}
adamc@448:                 -> 'context -> 'state -> Elab.exp -> 'state
adamc@10: end
adamc@10: 
adamc@34: structure Sgn : sig
adamc@34:     datatype binder =
adamc@623:              RelK of string
adamc@623:            | RelC of string * Elab.kind
adamc@792:            | NamedC of string * int * Elab.kind * Elab.con option
adamc@792:            | Str of string * int * Elab.sgn
adamc@792:            | Sgn of string * int * Elab.sgn
adamc@34: 
adamc@623:     val mapfoldB : {kind : ('context, Elab.kind', 'state, 'abort) Search.mapfolderB,
adamc@34:                     con : ('context, Elab.con', 'state, 'abort) Search.mapfolderB,
adamc@34:                     sgn_item : ('context, Elab.sgn_item', 'state, 'abort) Search.mapfolderB,
adamc@34:                     sgn : ('context, Elab.sgn', 'state, 'abort) Search.mapfolderB,
adamc@34:                     bind : 'context * binder -> 'context}
adamc@34:                    -> ('context, Elab.sgn, 'state, 'abort) Search.mapfolderB
adamc@34: 
adamc@34: 
adamc@34:     val mapfold : {kind : (Elab.kind', 'state, 'abort) Search.mapfolder,
adamc@34:                    con : (Elab.con', 'state, 'abort) Search.mapfolder,
adamc@34:                    sgn_item : (Elab.sgn_item', 'state, 'abort) Search.mapfolder,
adamc@34:                    sgn : (Elab.sgn', 'state, 'abort) Search.mapfolder}
adamc@34:                   -> (Elab.sgn, 'state, 'abort) Search.mapfolder
adamc@34: 
adamc@34:     val map : {kind : Elab.kind' -> Elab.kind',
adamc@34:                con : Elab.con' -> Elab.con',
adamc@34:                sgn_item : Elab.sgn_item' -> Elab.sgn_item',
adamc@34:                sgn : Elab.sgn' -> Elab.sgn'}
adamc@34:               -> Elab.sgn -> Elab.sgn
adamc@34: 
adamc@792:     val mapB : {kind : 'context -> Elab.kind' -> Elab.kind',
adamc@792:                 con : 'context -> Elab.con' -> Elab.con',
adamc@792:                 sgn_item : 'context -> Elab.sgn_item' -> Elab.sgn_item',
adamc@792:                 sgn : 'context -> Elab.sgn' -> Elab.sgn',
adamc@792:                 bind : 'context * binder -> 'context}
adamc@792:                -> 'context -> Elab.sgn -> Elab.sgn
adamc@792:                               
adamc@2: end
adamc@34: 
adamc@76: structure Decl : sig
adamc@76:     datatype binder =
adamc@623:              RelK of string
adamc@623:            | RelC of string * Elab.kind
adamc@792:            | NamedC of string * int * Elab.kind * Elab.con option
adamc@76:            | RelE of string * Elab.con
adamc@76:            | NamedE of string * Elab.con
adam@1345:            | Str of string * int * Elab.sgn
adam@1345:            | Sgn of string * int * Elab.sgn
adamc@76: 
adamc@623:     val mapfoldB : {kind : ('context, Elab.kind', 'state, 'abort) Search.mapfolderB,
adamc@76:                     con : ('context, Elab.con', 'state, 'abort) Search.mapfolderB,
adamc@76:                     exp : ('context, Elab.exp', 'state, 'abort) Search.mapfolderB,
adamc@76:                     sgn_item : ('context, Elab.sgn_item', 'state, 'abort) Search.mapfolderB,
adamc@76:                     sgn : ('context, Elab.sgn', 'state, 'abort) Search.mapfolderB,
adamc@76:                     str : ('context, Elab.str', 'state, 'abort) Search.mapfolderB,
adamc@76:                     decl : ('context, Elab.decl', 'state, 'abort) Search.mapfolderB,
adamc@76:                     bind : 'context * binder -> 'context}
adamc@76:                    -> ('context, Elab.decl, 'state, 'abort) Search.mapfolderB
adamc@76:     val mapfold : {kind : (Elab.kind', 'state, 'abort) Search.mapfolder,
adamc@76:                    con : (Elab.con', 'state, 'abort) Search.mapfolder,
adamc@76:                    exp : (Elab.exp', 'state, 'abort) Search.mapfolder,
adamc@76:                    sgn_item : (Elab.sgn_item', 'state, 'abort) Search.mapfolder,
adamc@76:                    sgn : (Elab.sgn', 'state, 'abort) Search.mapfolder,
adamc@76:                    str : (Elab.str', 'state, 'abort) Search.mapfolder,
adamc@76:                    decl : (Elab.decl', 'state, 'abort) Search.mapfolder}
adamc@76:                   -> (Elab.decl, 'state, 'abort) Search.mapfolder
adamc@76:     val exists : {kind : Elab.kind' -> bool,
adamc@76:                   con : Elab.con' -> bool,
adamc@76:                   exp : Elab.exp' -> bool,
adamc@76:                   sgn_item : Elab.sgn_item' -> bool,
adamc@76:                   sgn : Elab.sgn' -> bool,
adamc@76:                   str : Elab.str' -> bool,
adamc@76:                   decl : Elab.decl' -> bool}
adamc@76:                  -> Elab.decl -> bool
adamc@76:     val search : {kind : Elab.kind' -> 'a option,
adamc@76:                   con : Elab.con' -> 'a option,
adamc@76:                   exp : Elab.exp' -> 'a option,
adamc@76:                   sgn_item : Elab.sgn_item' -> 'a option,
adamc@76:                   sgn : Elab.sgn' -> 'a option,
adamc@76:                   str : Elab.str' -> 'a option,
adamc@76:                   decl : Elab.decl' -> 'a option}
adamc@76:                  -> Elab.decl -> 'a option
adamc@448: 
adamc@623:     val foldMapB : {kind : 'context * Elab.kind' * 'state -> Elab.kind' * 'state,
adamc@448:                     con : 'context * Elab.con' * 'state -> Elab.con' * 'state,
adamc@448:                     exp : 'context * Elab.exp' * 'state -> Elab.exp' * 'state,
adamc@448:                     sgn_item : 'context * Elab.sgn_item' * 'state -> Elab.sgn_item' * 'state,
adamc@448:                     sgn : 'context * Elab.sgn' * 'state -> Elab.sgn' * 'state,
adamc@448:                     str : 'context * Elab.str' * 'state -> Elab.str' * 'state,
adamc@448:                     decl : 'context * Elab.decl' * 'state -> Elab.decl' * 'state,
adamc@448:                     bind : 'context * binder -> 'context}
adamc@448:                    -> 'context -> 'state -> Elab.decl -> Elab.decl * 'state
adam@1345: 
adam@1345:     val map : {kind : Elab.kind' -> Elab.kind',
adam@1345:                con : Elab.con' -> Elab.con',
adam@1345:                exp : Elab.exp' -> Elab.exp',
adam@1345:                sgn_item : Elab.sgn_item' -> Elab.sgn_item',
adam@1345:                sgn : Elab.sgn' -> Elab.sgn',
adam@1345:                str : Elab.str' -> Elab.str',
adam@1345:                decl : Elab.decl' -> Elab.decl'}
adam@1345:               -> Elab.decl -> Elab.decl
adam@1345: 
adam@1345:     val mapB : {kind : 'context -> Elab.kind' -> Elab.kind',
adam@1345:                 con : 'context -> Elab.con' -> Elab.con',
adam@1345:                 exp : 'context -> Elab.exp' -> Elab.exp',
adam@1345:                 sgn_item : 'context -> Elab.sgn_item' -> Elab.sgn_item',
adam@1345:                 sgn : 'context -> Elab.sgn' -> Elab.sgn',
adam@1345:                 str : 'context -> Elab.str' -> Elab.str',
adam@1345:                 decl : 'context -> Elab.decl' -> Elab.decl',
adam@1345:                 bind : 'context * binder -> 'context}
adam@1345:                -> 'context -> Elab.decl -> Elab.decl
adam@1732: 
adam@1732:     val fold : {kind : Elab.kind' * 'state -> 'state,
adam@1732:                con : Elab.con' * 'state -> 'state,
adam@1732:                exp : Elab.exp' * 'state -> 'state,
adam@1732:                sgn_item : Elab.sgn_item' * 'state -> 'state,
adam@1732:                sgn : Elab.sgn' * 'state -> 'state,
adam@1732:                str : Elab.str' * 'state -> 'state,
adam@1732:                decl : Elab.decl' * 'state -> 'state}
adam@1732:               -> 'state -> Elab.decl -> 'state
adamc@448: end
adamc@448: 
adamc@448: structure File : sig
adamc@448:     val maxName : Elab.file -> int
adam@1584: 
adam@1584:     val findDecl : (Elab.decl -> bool) -> Elab.file -> Elab.decl option
adamc@34: end
adamc@76: 
adamc@76: end