Polymorphic variants for basic types?

From: Markus Mottl (mottl@miss.wu-wien.ac.at)
Date: Sat Jan 15 2000 - 20:06:30 MET

  • Next message: Gerd Stolpmann: "How to load the bytecode interpreter from Perl"

    Hello,

    this idea has probably already been considered: what do you think about
    translating basic values prefixed by "`" to polymorphic variants
    automatically during compilation?

    E.g.

      match foo with match foo with
      | `"Some string" -> ... to | `String "Some string" -> ...
      | `42 -> | `Int 42 -> ...
      | `[x; y; z] -> | `List [x; y; z] -> ...
      ...
      
    As far as I can see, this would not be a difficult thing to do, because it
    only seems to require syntactic information. Probably even the preprocessor
    could be used for this.

    Some nice things would be possible then, like the one above or conveniently
    writing down complex datastructures (e.g. trees with arbitrary numbers of
    subnodes):

      let tree = `[ `3; `[`4; `5]; `[ `[`6] ] ] in ...

    which is probably much easier to write than:

      let tree =
        `List [ `Int 3;
                `List [`Int 4; `Int 5];
                `List [ `List [`Int 6] ] ] in ...

    Anyway, this is just a small feature suggestion - I am sure there are more
    important language properties at the moment to reason about.

    Regards,
    Markus Mottl

    -- 
    Markus Mottl, mottl@miss.wu-wien.ac.at, http://miss.wu-wien.ac.at/~mottl
    



    This archive was generated by hypermail 2b29 : Sun Jan 16 2000 - 22:33:38 MET