adam@1847: (* Copyright (c) 2008, 2013, Adam Chlipala adamc@26: * All rights reserved. adamc@26: * adamc@26: * Redistribution and use in source and binary forms, with or without adamc@26: * modification, are permitted provided that the following conditions are met: adamc@26: * adamc@26: * - Redistributions of source code must retain the above copyright notice, adamc@26: * this list of conditions and the following disclaimer. adamc@26: * - Redistributions in binary form must reproduce the above copyright notice, adamc@26: * this list of conditions and the following disclaimer in the documentation adamc@26: * and/or other materials provided with the distribution. adamc@26: * - The names of contributors may not be used to endorse or promote products adamc@26: * derived from this software without specific prior written permission. adamc@26: * adamc@26: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" adamc@26: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE adamc@26: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE adamc@26: * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE ziv@2218: * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR adamc@26: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF adamc@26: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS adamc@26: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN adamc@26: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) adamc@26: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE adamc@26: * POSSIBILITY OF SUCH DAMAGE. adamc@26: *) adamc@26: adamc@26: signature MONO_UTIL = sig adamc@26: adamc@26: structure Typ : sig adamc@109: val compare : Mono.typ * Mono.typ -> order adamc@109: val sortFields : (string * Mono.typ) list -> (string * Mono.typ) list adamc@109: adamc@26: val mapfold : (Mono.typ', 'state, 'abort) Search.mapfolder adamc@26: -> (Mono.typ, 'state, 'abort) Search.mapfolder adamc@26: adamc@26: val map : (Mono.typ' -> Mono.typ') adamc@26: -> Mono.typ -> Mono.typ adamc@26: adamc@26: val fold : (Mono.typ' * 'state -> 'state) adamc@26: -> 'state -> Mono.typ -> 'state adamc@26: adamc@26: val exists : (Mono.typ' -> bool) -> Mono.typ -> bool adamc@26: end adamc@26: adamc@26: structure Exp : sig adamc@26: datatype binder = adamc@168: Datatype of string * int * (string * int * Mono.typ option) list adamc@26: | RelE of string * Mono.typ adamc@109: | NamedE of string * int * Mono.typ * Mono.exp option * string adamc@26: adamc@26: val mapfoldB : {typ : (Mono.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : ('typtext, Mono.exp', 'state, 'abort) Search.mapfolderB, adamc@26: bind : 'typtext * binder -> 'typtext} adamc@26: -> ('typtext, Mono.exp, 'state, 'abort) Search.mapfolderB adamc@26: val mapfold : {typ : (Mono.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : (Mono.exp', 'state, 'abort) Search.mapfolder} adamc@26: -> (Mono.exp, 'state, 'abort) Search.mapfolder adamc@26: adamc@26: val map : {typ : Mono.typ' -> Mono.typ', adamc@26: exp : Mono.exp' -> Mono.exp'} adamc@26: -> Mono.exp -> Mono.exp adamc@26: val mapB : {typ : Mono.typ' -> Mono.typ', adamc@26: exp : 'typtext -> Mono.exp' -> Mono.exp', adamc@26: bind : 'typtext * binder -> 'typtext} adamc@26: -> 'typtext -> (Mono.exp -> Mono.exp) adamc@26: adamc@26: val fold : {typ : Mono.typ' * 'state -> 'state, adamc@26: exp : Mono.exp' * 'state -> 'state} adamc@26: -> 'state -> Mono.exp -> 'state ziv@2218: adamc@26: val exists : {typ : Mono.typ' -> bool, adamc@26: exp : Mono.exp' -> bool} -> Mono.exp -> bool adamc@567: adamc@919: val existsB : {typ : Mono.typ' -> bool, adamc@919: exp : 'context * Mono.exp' -> bool, adamc@919: bind : 'context * binder -> 'context} -> 'context -> Mono.exp -> bool adamc@919: adamc@567: val foldB : {typ : Mono.typ' * 'state -> 'state, adamc@567: exp : 'context * Mono.exp' * 'state -> 'state, adamc@567: bind : 'context * binder -> 'context} adamc@567: -> 'context -> 'state -> Mono.exp -> 'state adam@1612: adam@1612: val appLoc : (Mono.exp -> unit) -> Mono.exp -> unit adamc@26: end adamc@26: adamc@26: structure Decl : sig adamc@26: datatype binder = datatype Exp.binder adamc@26: adamc@26: val mapfoldB : {typ : (Mono.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : ('typtext, Mono.exp', 'state, 'abort) Search.mapfolderB, adamc@26: decl : ('typtext, Mono.decl', 'state, 'abort) Search.mapfolderB, adamc@26: bind : 'typtext * binder -> 'typtext} adamc@26: -> ('typtext, Mono.decl, 'state, 'abort) Search.mapfolderB adamc@26: val mapfold : {typ : (Mono.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : (Mono.exp', 'state, 'abort) Search.mapfolder, adamc@26: decl : (Mono.decl', 'state, 'abort) Search.mapfolder} adamc@26: -> (Mono.decl, 'state, 'abort) Search.mapfolder adamc@26: adamc@26: val fold : {typ : Mono.typ' * 'state -> 'state, adamc@26: exp : Mono.exp' * 'state -> 'state, adamc@26: decl : Mono.decl' * 'state -> 'state} adamc@26: -> 'state -> Mono.decl -> 'state adamc@506: adamc@506: val map : {typ : Mono.typ' -> Mono.typ', adamc@506: exp : Mono.exp' -> Mono.exp', adamc@506: decl : Mono.decl' -> Mono.decl'} adamc@506: -> Mono.decl -> Mono.decl adamc@567: adam@1800: val foldMap : {typ : Mono.typ' * 'state -> Mono.typ' * 'state, adam@1800: exp : Mono.exp' * 'state -> Mono.exp' * 'state, adam@1800: decl : Mono.decl' * 'state -> Mono.decl' * 'state} adam@1800: -> 'state -> Mono.decl -> Mono.decl * 'state adam@1800: adamc@567: val foldMapB : {typ : Mono.typ' * 'state -> Mono.typ' * 'state, adamc@567: exp : 'context * Mono.exp' * 'state -> Mono.exp' * 'state, adamc@567: decl : 'context * Mono.decl' * 'state -> Mono.decl' * 'state, adamc@567: bind : 'context * binder -> 'context} adamc@567: -> 'context -> 'state -> Mono.decl -> Mono.decl * 'state adam@1847: adam@1847: val exists : {typ : Mono.typ' -> bool, adam@1847: exp : Mono.exp' -> bool, adam@1847: decl : Mono.decl' -> bool} -> Mono.decl -> bool adamc@26: end adamc@26: adamc@26: structure File : sig adamc@26: datatype binder = datatype Exp.binder adamc@26: adamc@26: val mapfoldB : {typ : (Mono.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : ('typtext, Mono.exp', 'state, 'abort) Search.mapfolderB, adamc@26: decl : ('typtext, Mono.decl', 'state, 'abort) Search.mapfolderB, adamc@26: bind : 'typtext * binder -> 'typtext} adamc@26: -> ('typtext, Mono.file, 'state, 'abort) Search.mapfolderB adamc@26: adamc@26: val mapfold : {typ : (Mono.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : (Mono.exp', 'state, 'abort) Search.mapfolder, adamc@26: decl : (Mono.decl', 'state, 'abort) Search.mapfolder} adamc@26: -> (Mono.file, 'state, 'abort) Search.mapfolder adamc@26: adamc@26: val mapB : {typ : Mono.typ' -> Mono.typ', adamc@26: exp : 'typtext -> Mono.exp' -> Mono.exp', adamc@26: decl : 'typtext -> Mono.decl' -> Mono.decl', adamc@26: bind : 'typtext * binder -> 'typtext} adamc@26: -> 'typtext -> Mono.file -> Mono.file adamc@26: adamc@96: val map : {typ : Mono.typ' -> Mono.typ', adamc@96: exp : Mono.exp' -> Mono.exp', adamc@96: decl : Mono.decl' -> Mono.decl'} adamc@96: -> Mono.file -> Mono.file adamc@96: adamc@26: val fold : {typ : Mono.typ' * 'state -> 'state, adamc@26: exp : Mono.exp' * 'state -> 'state, adamc@26: decl : Mono.decl' * 'state -> 'state} adamc@26: -> 'state -> Mono.file -> 'state adamc@506: adamc@506: val maxName : Mono.file -> int adam@1612: adam@1612: val appLoc : (Mono.exp -> unit) -> Mono.file -> unit adamc@26: end adamc@26: adamc@26: end