Newsgroups: comp.lang.functional
From: Neelakantan Krishnaswami <ne...@cs.cmu.edu>
Date: Mon, 28 Nov 2005 23:45:27 +0000 (UTC)
Local: Mon, Nov 28 2005 6:45 pm
Subject: Re: FP-style map over set
In article <dmf24v$1a8...@news2.ipartners.pl>, RobertSzefler wrote: So, the difference between a list and a finite set is that a list is a > Well, "list" also is an ADT and Haskell (and other FPL's) have these free algebra, and sets aren't. You can construct a list of elements of type t using the following signature: nil : set There are no equations between the lists you build up using nil and forall x, y, rest. add x (add y rest) == (add y (add x rest)) and forall x, rest. add x (add x rest) == add x rest The first equation says that changing the order of insertion doesn't Assuming that you have a function choose : set -> (t * set) option which satisfies the equations choose nil == None and forall x, rest. there exist x', rest'. then you can define a perfectly good map function in the obvious way: fun map f list = Now, you can show the correctness of map with a simple inductive If I understand you correctly, the reason you're worried arises from structure IntSet = val nil = [] val add (x, set) = x :: set fun choose [] = NONE You are worried that if you have val s = add(1, add(2, nil)) then s and r represent the same set {1,2}, but that calls to s and choose(s) evaluates to SOME(1, {2}) and choose(r) evaluates to SOME(2, {1}) This superficially looks like it breaks the equational reasoning forall x, rest. there exist x', rest'. Here, we very carefully DON'T say that choose (add x rest) == Some(x, rest) Instead, we use an existential quantifier to say that choose returns -- You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
| ||||||||||||||