Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.haskell > #334 > unrolled thread

using list comprehension

Started bypip7kids@gmail.com
First post2015-07-24 02:06 -0700
Last post2015-07-24 03:45 -0700
Articles 3 — 2 participants

Back to article view | Back to comp.lang.haskell


Contents

  using list comprehension pip7kids@gmail.com - 2015-07-24 02:06 -0700
    Re: using list comprehension Mark Carroll <mtbc@bcs.org> - 2015-07-24 10:58 +0100
    Re: using list comprehension pip7kids@gmail.com - 2015-07-24 03:45 -0700

#334 — using list comprehension

Frompip7kids@gmail.com
Date2015-07-24 02:06 -0700
Subjectusing list comprehension
Message-ID<4641db20-a273-4a84-bbba-9f2b5aeb5bb6@googlegroups.com>
Hi
I'm trying to understand if I can use the following code in a list comprehension.

The following works for 2 values - 456.78 44
perc = 44.56
returns nav shares =
  let aum = nav * shares
      rets = aum ^ 2
      val = 1000 / perc
      rem = aum / rets  + val 
  in aum / rets * rem ^ 4

main = do 
   print(returns 456.78 44) -- result is 12.620116562240828

.......... however, what I would like to achieve is - can I use the above logic for many values in a list comprehension?

eg

nav = [1,2,3,4]
shares = [5,6,7,8]

I would now like my "return" function to act on the list's nav and shares.
Is this possible and how.

Regards

[toc] | [next] | [standalone]


#335

FromMark Carroll <mtbc@bcs.org>
Date2015-07-24 10:58 +0100
Message-ID<87pp3h7u79.fsf@ixod.org>
In reply to#334
pip7kids@gmail.com writes:
(snip)
> The following works for 2 values - 456.78 44
> perc = 44.56
> returns nav shares =
(snip)
> .......... however, what I would like to achieve is - can I use the above logic for many values in a list comprehension?
>
> eg
>
> nav = [1,2,3,4]
> shares = [5,6,7,8]
>
> I would now like my "return" function to act on the list's nav and shares.
> Is this possible and how.

Would "zipWith returns nav shares" do what you want?

--Mark

[toc] | [prev] | [next] | [standalone]


#336

Frompip7kids@gmail.com
Date2015-07-24 03:45 -0700
Message-ID<68dd5a82-db30-4e39-b601-95cdc2571aca@googlegroups.com>
In reply to#334
On Friday, 24 July 2015 10:06:56 UTC+1, pip7...@gmail.com  wrote:
> Hi
> I'm trying to understand if I can use the following code in a list comprehension.
> 
> The following works for 2 values - 456.78 44
> perc = 44.56
> returns nav shares =
>   let aum = nav * shares
>       rets = aum ^ 2
>       val = 1000 / perc
>       rem = aum / rets  + val 
>   in aum / rets * rem ^ 4
> 
> main = do 
>    print(returns 456.78 44) -- result is 12.620116562240828
> 
> .......... however, what I would like to achieve is - can I use the above logic for many values in a list comprehension?
> 
> eg
> 
> nav = [1,2,3,4]
> shares = [5,6,7,8]
> 
> I would now like my "return" function to act on the list's nav and shares.
> Is this possible and how.
> 
> Regards

Thats simply brilliant - thanks

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.haskell


csiph-web