On Mon, Sep 09, 2013 at 05:48:46PM +0200, Klaus Aehlig wrote:
> On Mon, Sep 09, 2013 at 05:15:02PM +0200, Jose A. Lopes wrote:
> > Add type 'FrozenSet' that wrap a Haskell 'Set', and a guarded
> > constructor for this type and a 'PyValue' instance.
> > 
> > Signed-off-by: Jose A. Lopes <[email protected]>
> > ---
> >  Makefile.am                 |  1 +
> >  src/Ganeti/ConstantUtils.hs | 59 
> > +++++++++++++++++++++++++++++++++++++++++++++
> >  2 files changed, 60 insertions(+)
> >  create mode 100644 src/Ganeti/ConstantUtils.hs
> 
> > +mkSet :: Ord a => [a] -> FrozenSet a
> > +mkSet xs
> > +  | length xs == length (nub xs) =
> > +    FrozenSet (Set.fromList xs)
> > +  | otherwise =
> > +    error "ConstantUtils: mkSet: list contains duplicate elements"
> 
> Again, what is the rationale of having an error instead of a graceful
> 
>   mkSet :: Ord a => [a] -> FrozenSet a
>   mkSet = FrozenSet . Set.fromList
> 
> (My reading fo the specification is that Set.fromList will
> remove duplicates, so not even necessary to have a '. nub' at
> the end of the second line)?
> 
> First, your test introduces a semantics different from how we
> usualy think of lists as sets, e.g., via the `elem` predicate.
> Seconly, an error neither assures immediate failure
> of the program (in case you're aiming at "compile-time" errors,
> i.e., make code generation fail), nor can it be handled, as this
> would be the case with the "fail" of a monad like Maybe, Either String,
> or similar.
> 
> So, when hiding error in a function with pure signature, I'd like
> to have, at the very least, a comment properly explaining why this is
> the right thing to do---if it really is.

I am ok with either solution.  I was just copying the functionality of
the Python function 'UniqueFrozenset' in 'lib/compat.py', which checks
if there are duplicate elements and aborts the program.  If you
prefer, I can change the code as you suggested before.

What do you want to do ?

Thanks,
Jose

Reply via email to