fellow Monks,

I have been looking at exception handling in a few projects, as well as discussing functional programming with a few Scala developers. I really like the ideal of referentially transparent errors as an output of a function. This makes it possible to reason equationally about things.

So I have thought a bit about trying to create a tied hash type, which would always evaluate as undef in a scalar context, but would have fields for error messages, inputs that are out of bounds, etc. This could be returned from a function in place of an undef as a failure value.

Where I am having some difficulties is in finding a way to apply this to my work with Moose. In particular, the question is how to apply this in lazy builders in particular. I would assume that if a value in a lazy builder does not validate, it should return the error instead of raising it as an exception.

Has anyone tried to do this before? How deep am I looking at regarding modifications?


In reply to How to make Moose more "functional"? by einhverfr

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.