adamc@26: (* Copyright (c) 2008, 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 adamc@26: * 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 FLAT_UTIL = sig adamc@26: adamc@26: structure Typ : sig adamc@26: val mapfold : (Flat.typ', 'state, 'abort) Search.mapfolder adamc@26: -> (Flat.typ, 'state, 'abort) Search.mapfolder adamc@26: adamc@26: val map : (Flat.typ' -> Flat.typ') adamc@26: -> Flat.typ -> Flat.typ adamc@26: adamc@26: val fold : (Flat.typ' * 'state -> 'state) adamc@26: -> 'state -> Flat.typ -> 'state adamc@26: adamc@26: val exists : (Flat.typ' -> bool) -> Flat.typ -> bool adamc@26: end adamc@26: adamc@26: structure Exp : sig adamc@26: datatype binder = adamc@26: NamedT of string * int * Flat.typ option adamc@26: | RelE of string * Flat.typ adamc@26: | NamedE of string * int * Flat.typ * Flat.exp option adamc@26: adamc@26: val mapfoldB : {typ : (Flat.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : ('typtext, Flat.exp', 'state, 'abort) Search.mapfolderB, adamc@26: bind : 'typtext * binder -> 'typtext} adamc@26: -> ('typtext, Flat.exp, 'state, 'abort) Search.mapfolderB adamc@26: val mapfold : {typ : (Flat.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : (Flat.exp', 'state, 'abort) Search.mapfolder} adamc@26: -> (Flat.exp, 'state, 'abort) Search.mapfolder adamc@26: adamc@26: val map : {typ : Flat.typ' -> Flat.typ', adamc@26: exp : Flat.exp' -> Flat.exp'} adamc@26: -> Flat.exp -> Flat.exp adamc@26: val mapB : {typ : Flat.typ' -> Flat.typ', adamc@26: exp : 'typtext -> Flat.exp' -> Flat.exp', adamc@26: bind : 'typtext * binder -> 'typtext} adamc@26: -> 'typtext -> (Flat.exp -> Flat.exp) adamc@26: adamc@26: val fold : {typ : Flat.typ' * 'state -> 'state, adamc@26: exp : Flat.exp' * 'state -> 'state} adamc@26: -> 'state -> Flat.exp -> 'state adamc@26: adamc@26: val exists : {typ : Flat.typ' -> bool, adamc@26: exp : Flat.exp' -> bool} -> Flat.exp -> bool adamc@26: end adamc@26: adamc@26: structure Decl : sig adamc@26: datatype binder = datatype Exp.binder adamc@26: adamc@26: val mapfoldB : {typ : (Flat.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : ('typtext, Flat.exp', 'state, 'abort) Search.mapfolderB, adamc@26: decl : ('typtext, Flat.decl', 'state, 'abort) Search.mapfolderB, adamc@26: bind : 'typtext * binder -> 'typtext} adamc@26: -> ('typtext, Flat.decl, 'state, 'abort) Search.mapfolderB adamc@26: val mapfold : {typ : (Flat.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : (Flat.exp', 'state, 'abort) Search.mapfolder, adamc@26: decl : (Flat.decl', 'state, 'abort) Search.mapfolder} adamc@26: -> (Flat.decl, 'state, 'abort) Search.mapfolder adamc@26: adamc@26: val fold : {typ : Flat.typ' * 'state -> 'state, adamc@26: exp : Flat.exp' * 'state -> 'state, adamc@26: decl : Flat.decl' * 'state -> 'state} adamc@26: -> 'state -> Flat.decl -> 'state adamc@26: end adamc@26: adamc@26: structure File : sig adamc@26: datatype binder = adamc@26: NamedT of string * int * Flat.typ option adamc@26: | RelE of string * Flat.typ adamc@26: | NamedE of string * int * Flat.typ * Flat.exp option adamc@26: | F of int * string * Flat.typ * Flat.typ * Flat.exp adamc@26: adamc@26: val mapfoldB : {typ : (Flat.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : ('typtext, Flat.exp', 'state, 'abort) Search.mapfolderB, adamc@26: decl : ('typtext, Flat.decl', 'state, 'abort) Search.mapfolderB, adamc@26: bind : 'typtext * binder -> 'typtext} adamc@26: -> ('typtext, Flat.file, 'state, 'abort) Search.mapfolderB adamc@26: adamc@26: val mapfold : {typ : (Flat.typ', 'state, 'abort) Search.mapfolder, adamc@26: exp : (Flat.exp', 'state, 'abort) Search.mapfolder, adamc@26: decl : (Flat.decl', 'state, 'abort) Search.mapfolder} adamc@26: -> (Flat.file, 'state, 'abort) Search.mapfolder adamc@26: adamc@26: val mapB : {typ : Flat.typ' -> Flat.typ', adamc@26: exp : 'typtext -> Flat.exp' -> Flat.exp', adamc@26: decl : 'typtext -> Flat.decl' -> Flat.decl', adamc@26: bind : 'typtext * binder -> 'typtext} adamc@26: -> 'typtext -> Flat.file -> Flat.file adamc@26: adamc@26: val fold : {typ : Flat.typ' * 'state -> 'state, adamc@26: exp : Flat.exp' * 'state -> 'state, adamc@26: decl : Flat.decl' * 'state -> 'state} adamc@26: -> 'state -> Flat.file -> 'state adamc@26: end adamc@26: adamc@26: end