tabulators
Matthew Fluet
Matthew Fluet <fluet@cs.cornell.edu>
Fri, 25 Jan 2002 15:42:21 -0500 (EST)
> So, your solution accumulates the results in a list, and at the end
> reverses the list then calls unfold. Makes sense, but is slow, and is
> again using lists as the universal intermediate format.
Agreed. I wasn't claiming that they were necessarily efficient
conversions, but they do exist.
> > > signature ITERATE2 =
> > > sig
> > > type 'a t
> > > type 'a state
> > > val iterate: 'a t -> {next: 'a state -> ('a * 'a state) option,
> > > start: 'a state}
> > > end
> >
> > I still don't get why this (or CONSTRUCT2) is useful? If you build it up
> > using C7to2, then you don't seem to have any choice in the state.
>
> You don't. It's just that CONSTRUCT2 and ITERATE2 can be implemented
> purely functionally, while CONSTRUCT1 and ITERATE1 can't.
??? Again, what's the definition of "purely functinally"? I thought we
established a purely functional VectorConstruct (and I've got
ListConstruct, ListIterate, and VectorIterate), all with *1 signatures.
Agreed, VectorConstruct by building up a list, Vector.fromList, and
Vector.rev isn't as efficient as an "in Basis" implementation with unsafe
operations. But, I don't see any efficiency problems with:
structure VectorIterate : ITERATE =
struct
type 'a t = 'a vector
datatype 'a iter = Iter of unit -> ('a * 'a iter) option
fun iterate v =
let
val n = Vector.length v
fun mkIter i =
if i >= n
then Iter (fn () => NONE)
else Iter (fn () => SOME (Vector.sub (v, i), mkIter (i + 1)))
in
mkIter 0
end
end