(* * This file is a component of PropPlan - a model-based planner * Copyright (C) 2000-2007 Michael Paul Fourman * homepages.inf.ed.ac.uk/mfourman/tools/propplan * sourceforge.net/projects/propplan * michael.fourman (AT) gmail.com * * This program is free software: you can redistribute it and/or modify * it under the terms of version 3 of the GNU Affero General Public License * as published by the Free Software Foundation. * * 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 the file COPYING, a copy of the GNU Affero * Public License, along with this program. * If not, see . * $Id: DICTIONARY.ML,v 1.1 2007/12/30 15:31:25 michaelfourman Exp $ *) signature DICTIONARY = sig type Key type 'a Dict exception Lookup val empty : 'a Dict val lookup : 'a Dict -> Key -> 'a val remove : Key * 'a Dict -> 'a Dict val enter : (Key * 'a) * 'a Dict -> 'a Dict end functor DICTIONARY( eqtype Key ):DICTIONARY = struct type Key = Key exception Lookup datatype 'a Dict = D of (Key * 'a) list val empty = D [] fun lookup (D((k,e)::t)) key = if(k = key)then e else lookup (D t) key | lookup _ _ = raise Lookup fun rem _ [] = [] | rem key ((entry as (k,_))::t) = if(k = key) then rem key t (* this should be redundant *) else entry :: rem key t fun ent ((k,e), []) = [(k, e)] | ent ((k,e), ((k',e') :: entries)) = if k = k' then raise Lookup else (k',e') :: ent ((k,e), entries) fun enter (ke, D entries) = D (ent(ke, entries) ) fun remove (key, D entries) = D(rem key entries) fun alist (D l) = l fun size (D []) = 0 | size (D (_ :: t)) = 1 + size (D t); end;