On 2014-25-06 18:32, Andy Parker wrote:
On Wed, Jun 25, 2014 at 5:27 AM, Trevor Vaughan <[email protected]
<mailto:[email protected]>> wrote:

    Henrik,

    Just got done reading through this and it looks quite useful.

    I do have a common use case that I'd like to see incorporated if
    possible though.

    I would like to have users be able to input either a String or an
    Array into many variables and have String instances auto-cast to a
    single unit Array.


You can do something like that right now. The type of the parameter is
Variant[String, Array[String]], then once you get the value you need to
convert that into a common type. For that kind of a thing, I think there
would be a function to convert the type, but I'm not sure that we would
put such a function inside puppet itself.

    This would allow me to simplify code where I either have to cast the
    variable myself or have an if/else chain to do different things
    based on the input type.


We've made the decision that puppet will try to have as few surprises as
possible in the language and so auto-conversion of values between types
is kept to a minimum. The only one we really have right now is
Numeric<->String and stringification in string interpolations.


I don't think the value transformation part is something we want to support in general for a parameter; similar things can be done in a (ruby) resource type. We are looking into how you can specify types in the puppet language, I can imagine things like this being one there, were you declare a type to have derived attributes (they are computed), while you have the real user entered data in an attribute with storage, or the other way around, a complex value is split up on assignment, and (possibly) put back together when reading it.

Basically I envison these types to have functions (written in the puppet language) inside them for things like derived values, munging, transformation.

I expect the types to be callable to create new instances. Say you invent your data type that accepts Variant[String, Array[String]] when created, and then maps that to always be multi valued. You would give it an apropriate name - here inventing Strings as the type - the user writes Strings('one string'), Strings('one string', 'another'), or
Strings(['one', 'two', 'three']), or whatever you feel like supporting.
The receiving end then naturally only accepts something of Strings type.
You know do not have to do any checking since all transformations are done in the Strings type.

(These ideas are not fully worked out, but I imagine something along those lines).

If you like to write a assert and transform function (right now) that would not be too hard, but you would miss the convenience of directly typing the parameters (except for the checking that can be made with something like Variant[String, Array[String]].

I don't see us adding automatic data conversion for parameters; although convenient from one vantage point, it is also a constant source of problems, causes performance issues, and can be mysterious to users.

- henrik

--

Visit my Blog "Puppet on the Edge"
http://puppet-on-the-edge.blogspot.se/

--
You received this message because you are subscribed to the Google Groups "Puppet 
Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-dev/lofiji%242sg%241%40ger.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to