« Return to Thread: "ocaml_beginners"::[] De-unifying variant types

Re: "ocaml_beginners"::[] De-unifying variant types

by William D. Neumann :: Rate this Message:

Reply to Author | View in Thread

On Wed, 25 Jul 2007, cultural_sublimation wrote:

> My question is the following: how do I undo the unification of movie_t
> and actor_t, so that externally, the signatures of these functions are
> different? (listed below).  I don't want the caller to be bothering
> with matches, and quite frankly, the fact that movie_t and actor_t were
> unified is an implementation detail, used only to avoid the duplication
> of the process_query code.
>
>
>  val process_movies : string array array -> movie_t array
>  val process_actors : string array array -> actor_t array

Well, unfortunately, if the output of the same function, you're out of
luck, as they have to share the same output type.  You'd need to offer up
a set of refinement functions for each of the cases you want to separate
out, e.g.

let refine_movie = function Movie m -> m | _ -> assert false;;
let refine_actor = function Actor a -> a | _ -> assert false;;

and so on.

I know it's not what you want, but unless you do a lot more work to hide
the way the type system works in OCaml, you're stuck with it, as you won't
be able to come up with a useful function of type string array array -> 'a
array, which is what you're asking for.

William D. Neumannn

---

"There's just so many extra children, we could just feed the
children to these tigers.  We don't need them, we're not doing
anything with them.

Tigers are noble and sleek; children are loud and messy."

         -- Neko Case

Life is unfair.  Kill yourself or get over it.
  -- Black Box Recorder

 « Return to Thread: "ocaml_beginners"::[] De-unifying variant types