Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  elegant handling of maybe and non-maybe      values (Kim-Ee Yeoh)


----------------------------------------------------------------------

Message: 1
Date: Fri, 21 Sep 2012 18:40:40 +0700
From: Kim-Ee Yeoh <[email protected]>
Subject: Re: [Haskell-beginners] elegant handling of maybe and
        non-maybe       values
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID:
        <CAPY+ZdRn=n8EJq262Td5cQ=qetct54nmh7f36kmvikiojvp...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

On Fri, Sep 21, 2012 at 8:25 AM, Christopher Howard <
[email protected]> wrote:

> But this seems rather clunky, especially if I want to attach the values in
> the new list to variable names afterwards.


Agreed. Haskell is not Lisp, so there's no attachment (TH notwithstanding)
to variable names ['a'..'z'] if that's what you're thinking.

Could you provide the concrete scenario of what you're trying to achieve?


-- Kim-Ee


On Fri, Sep 21, 2012 at 8:25 AM, Christopher Howard <
[email protected]> wrote:

> I have a code situation similar to this simplified one: Let's say that
> I've got a value v that is a Maybe type, and values x, y, and z that are
> not. x, y, and z are dependent on the value inside v. So I must provide
> default values for x, y, and z. An additional complication is that every
> calculation returns a new (possibly different) value for v. So, I could
> do something like this:
>
> code:
> --------
> let (v', x) = case v of
>                 Nothing -> (Nothing, defaultValueOfX)
>                 Just vValue -> f vValue in
> let (v'', y) = case v' of
>                  Nothing -> (Nothing, defaultValueOfY)
>                  Just vValue -> g vValue in
> let (v''', z) = case v'' of
>                   Nothing -> (Nothing, defaultValueOfZ)
>                   Just vValue -> h vValue in
> --------
>
> (f, g, h represent the calculations I am performing.) In the end, I need
> the values of x, y, and z, and the last v value.
>
> Obviously, the above solution is not very elegant, especially if I add a
> few more variables. My other thought was some kind of fold operation,
> where I store the functions (calculations) and the default values in a
> list, and then fold over the list, applying subsequent values of v or
> returning default values, as appropriate. But this seems rather clunky,
> especially if I want to attach the values in the new list to variable
> names afterwards.
>
> Is there a better approach?
>
> --
> frigidcode.com
> indicium.us
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20120921/8a8cf6d6/attachment-0001.htm>

------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 51, Issue 35
*****************************************

Reply via email to