[Swift-devel] [Bug 343] New: Add support for optional input and output files

Mihael Hategan hategan at mcs.anl.gov
Wed Apr 13 15:12:58 CDT 2011


Yes.

There might be variations on that, such as:

extractOne(value, defaultValue)
extract(array, defaultValue)

The first is obvious and the second would preserve the array shape.

On Wed, 2011-04-13 at 14:47 -0500, Jonathan Monette wrote:
> So then running a reduce on an array with optional arguments will
> return nothing.  However, if we need to reduce on the elements that
> were actually returned to the array we would call something like
> reduce( extract( a[] ), "+" )?  Is that what you are saying?  That in
> order to implement the optional output files a function would need to
> be defined to extract all the elements that are mapped from the
> optional array and this will all the user to run a reduce on the
> extracted values?
> 
> 
> If this is indeed how it will work then it will work fine for my
> case.  I am not sure what parvis is doing so I cannot say it will work
> for them but for the Montage wrappers it will work and will clean up
> code on my end.
> 
> On Tue, Apr 12, 2011 at 2:09 PM, Mihael Hategan <hategan at mcs.anl.gov>
> wrote:
>         I'm assuming we won't statically track optional data. In a
>         static typing
>         scenario, all optional data would need to be declared as such.
>         This
>         would be similar to the Maybe type in Haskell. I'm assuming we
>         don't
>         want to do that. Instead, optional types would be dynamic
>         types. This
>         would allow one to use an app defined with non-optional types
>         with
>         optional data.
>         
>         The typing rules would go something like this:
>         1. f: X -> Y
>          type(f(Nothing/X)) = Nothing/Y
>          type(f(Just X)) = Just Y
>         
>         2. For a composite type Y = X1 x X2 x... x Xn, type(Y) =
>         Nothing if any
>         Xi = Nothing, type(Y) = Just Y if all Xi = Just Xi.
>         
>         3. Corollary of 1 and 2 is that f: X1 x X2 -> Y, f(x1,
>         Nothing) =
>         f(Nothing, x2) = f(Nothing, Nothing) = Nothing. This can be
>         generalized.
>         
>         We should have an additional operator (catMaybes in Haskell)
>         which
>         extracts the present values from an array. In other words (and
>         we need a
>         name for it), ~([maybe x]) = [x}.
>         
>         There might be some contention here. I'm saying that a reduce
>         operating
>         on an array of optional data should by default return nothing
>         if any of
>         the array elements is a nothing. I think this should be done
>         if we are
>         to have consistency. Reduce is the successive application of
>         some
>         function to the elements of a list:
>         
>         reduce(a[], "+") = (...((a[0] + a[1]) + a[2]) + ... ) + a[n])
>         If, by the first rule (which I think is fundamental) "+"(Just
>         x,
>         Nothing) = Nothing, it can be easily seen that reduce(a[],
>         "+") =
>         Nothing if any a[i] = Nothing.
>         
>         In order to reduce only the Just values, there would need to
>         be a way to
>         extract only those from the array.
>         
>         Thoughts? Questions?
>         
>         Mihael
>         
>         
>         On Mon, 2011-04-11 at 14:20 -0500, Jonathan Monette wrote:
>         > Well the case I have in my scripts would be to only run the
>         reduce on
>         > the available elements in the array. I am not sure why the
>         other case
>         > would be valid. Not doin the reduce on the array because an
>         outfile
>         > was not mapped is the same as what swift currently does. The
>         only
>         > difference is that instead of causing the swift system to
>         fail it just
>         > tries to continue on the execution.
>         >
>         > On Apr 11, 2011 2:06 PM, "Mihael Hategan"
>         <hategan at mcs.anl.gov> wrote:
>         >
>         
>         
>         
> 
> 
> 
> -- 
> Any intelligent fool can make things bigger and more complex... It
> takes a touch of genius - and a lot of courage to move in the opposite
> direction.
> - Albert Einstein
> 
> 
> 





More information about the Swift-devel mailing list