List Info

Thread: Re: "ocaml_beginners"::[] quick question on mutually recursive types




Re: "ocaml_beginners"::[] quick question on mutually recursive types
country flaguser name
United States
2007-03-08 11:47:54

--- In ocaml_beginners%40yahoogroups.com">ocaml_beginnersyahoogroups.com, Jon Harrop <jon...> wrote:
&gt;
> On Monday 05 March 2007 18:51, overbored wrote:
&gt; > sure. i'm trying to write an (initially simple) object database.
the
> > rest of this paragraph is some background on this project. i've
tried
> > using python, haskell, and scala so far, with no luck. in python,
my
&gt; > code was turning mostly into a dynamic type-checker. in haskell,
> > dealing with cyclic references and mutable data structures
(basically
> > need to write my own non-functional hashsets, etc.) was a hassle
&gt; > whose magnitude i underestimated.
>;
> Can you explain why parts of your solution must be imperative?

databases are very stateful, so it appears to me that an imperative
approach is more fitting. fp is not (too) foreign to me, it just
can't be used for all problems; it's the dual of imperative. however,
if you have a concrete suggestion, i'd be happy to hear it (that was
not meant to sound snarky; also, it would be most useful if you
attempt to understand my code!). i've encountered a few 'efficient-
enough' purely functional data structures (okasaki's e.g. queues,
"edison"'s e.g. sets), but i fear they might not be suitable for the
problem at hand. an example of just one of the challenges is that of
cyclic references: see http://www.haskell.org/hawiki/TyingTheKnot for
a taste.

>
> > in scala, i got much farther, but
> > encountered a road block when it came to persistence - i basically
> > need to write my own pickling combinators for standard data
>; > structures like set, hashset, hashmap, etc. although this is a
> > slightly smaller roadblock, i'm considering this as an
opportunity to
> > learn ocaml.
&gt;
> You probably want to write picklers in OCaml too.

don't you get this for free with Marshal? (even if not, it at least
gives me marshalling of data structures like sets for free, right?)

>
> > for now, i'm first making sure i can do all the things i
> > need to do in ocaml before i rewrite the application logic again,
&gt; > such as persistence (Marshal) and whether the non-functional
paradigm
> > is usable (subject of this thread).
>
> That sounds like your proposed solution rather than the original
problem.
>
> > you can guess from my mention of persistence that i'm not too
worried
> > about performance at this point; i'd just like to get something
> > working, and reads/writes won't be very frequent (yet). otoh, i do
> > need to put thousands of references in these sets, so (at least in
> > the long run) i'd like efficiency here (Set.t ref are O(log(n))?).
>
> Set.find is O(log n), yes.

actually i meant insertion into/removal from ('mutating') a set.

>
> > i have these general questions:
> >
>; > - i realize Set is immutable, so should i build my own hashset
type
> > based on Hashtbl instead?
>
> I don't understand why you want to avoid purely functional data
structures.
> They are usually much simpler to use and can be faster.
>
> > any mutable hashset implementations for
> > ocaml? (will i be able to serialize these things with Marshal out-
of-
> > the-box?)
>
> The one you cite in your next e-mail is fine.
&gt;
> > - why can't i just use Sets like Hashtbls? why do i deal with
these
> > module functors, whereas i don't need to with Hashtbl or Marshal
or
&gt; > other (seemingly more complex than Set) utilities?
>
> Easy: OCaml's hash tables use an implicit hashing function that
doesn't always
> do what you want. With Sets, you provide the comparison function
explicitly.

vs. simply passing in the function as an arg to 'constructors' like
create and singleton?

>
> > i've perused the caml hump for any promising libs, to no avail.
any
&gt; > other suggestions on how to pursue my goal in ocaml (or any other
&gt; > language really) are much appreciated. thanks!
>
> Your task sounds like an interpreter for a dynamically-typed object
oriented
> language, which should be easy to do in many languages including
OCaml.
> However, I am concerned that you are still stating your proposed
solution
> (e.g. mutable sets) and not the original problem.

perhaps i may eventually layer on a simple querying/data manipulation
language, but for now i'm simply interested in providing some rpc
interface to clients. i'm trying to build a database of sorts, really
- not a language.

the reason i am interested in mutable sets is because that's my data
model. each 'object' has a number of 'many-to-many relationships' to
other objects, which manifest themselves as sets belonging to each
object. this means that the user accesses and mutates sets of object
references, and that these references are always bi-directional
(hence the cyclic data structures). this was a design decision based
on the expected usage pattern, since the user - me - finds this model
easiest to reason about for the intended applications; i have no
'impedance mismatch' with this interface. (i may later provide
convenience functions for looking up, and so my implementation may
evolve to use hashmaps instead, but there are enough other more
immediate challenges.)

this is the interface, but again if you have a suggestion for how to
implement this, i'd love to hear it.

&gt;
> --
> Dr Jon D Harrop, Flying Frog Consultancy Ltd.
>; OCaml for Scientists
> http://www.ffconsultancy.com/products/ocaml_for_scientists
>

__._,_.___
.

__,_._,___
[1]

about | contact  Other archives ( Real Estate discussion Medical topics )