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. haskell on OpenBSD 5.5 (Michael S)
2. A better way to "integrate" (Dimitri DeFigueiredo)
3. Re: A better way to "integrate" (Zhi An Ng)
4. Re: A better way to "integrate" (David McBride)
5. Haskell network sample (yang.zhao)
----------------------------------------------------------------------
Message: 1
Date: Tue, 20 May 2014 12:10:20 -0700 (PDT)
From: Michael S <[email protected]>
To: "[email protected]" <[email protected]>
Subject: [Haskell-beginners] haskell on OpenBSD 5.5
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="us-ascii"
Good day all,
I installed OpenBSD 5.5 in order to learn haskell.
There are a few glitches however. I installed the haskell-platform meta-package
and the issues I noticed are:
- hs-vector wouldn't install
- ghci wouldn't start, the message: unable to load package `integer-gmp'
Has anyone experienced the same issue? Is this happening on OpenBSD 5.4?
Is this OpenBSD specific?
Thanks in advance.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140520/b6ac397d/attachment-0001.html>
------------------------------
Message: 2
Date: Tue, 20 May 2014 20:12:59 -0600
From: Dimitri DeFigueiredo <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] A better way to "integrate"
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Awesome haskellers,
I am coding up a little function that aggregates "ask orders" in a
currency exchange.
Another way to look at it, is that the function takes as input a
histogram or fdf (in list format) and outputs the cumulative
distribution cdf (also in list format). So we are kind of "integrating"
the input list.
When given a list of asks in order of increasing price, the function
returns a list of points in the graph of the total supply curve.
Here's an example:
asks: returned list:
[ (Price 42, Volume 0.5), [ (Price 21, Volume 0.5),
(Price 50, Volume 1 ), (Price 21+50=71, Volume 1.5),
(Price 55, Volume 0.2)] (Price 21+50+11=82,Volume 1.7)]
the returned list gives us the total supply curve (price = y-axis,
quantity/volume = x-axis, so the order is flipped)
Summarizing
* We're adding up the volumes. The last volume on the list is the total
volume available for sale.
* We calculate the total amount to be paid to buy the current volume
(for each item in the list).
I have written up a simple function to do this:
aggregate :: Num a => [(a,a)] -> [(a,a)]
aggregate xs = aggregate' 0 0 xs
aggregate' :: Num a => a -> a -> [(a,a)] -> [(a,a)]
aggregate' _ _ [] = []
aggregate' accX accY ((x,y):ls) = let accX' = accX + x * y
accY' = accY + y
in (accX',accY') : aggregate'
accX' accY' ls
main = print $ aggregate [(42,0.5),(50,1),(55,0.2)]
However, this does not look very good to me and it feels like I'm
reinventing the wheel.
Question: Is there a better Haskell way to do this? I'm really anal
about making it easy to read.
Thanks!
Dimitri
------------------------------
Message: 3
Date: Wed, 21 May 2014 10:58:22 +0800
From: Zhi An Ng <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] A better way to "integrate"
Message-ID:
<CACgwX5fXixORa3LKDdCA=wb5_bca+kUj7xr=nw_85hKAv7i=c...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
??
Travesals can usually be implemented using folds, since your list is
increasing, I would think to use a foldl, this is my attempt:
foldl :: (a -> b -> a) -> a -> [b] -> a
prices = [(42, 0.5), (50, 1), (55, 0.2)]
agg = foldl accum []
where accum [] (price, volume) = [(price * volume, volume)]
accum xs (price, volume) =
let total = last xs
total_price = fst total
total_volume = snd total
cost = price * volume in
xs ++ [(total_price + cost, total_volume + volume)]
main = print $ agg prices
Best,
Zhi An
On Wed, May 21, 2014 at 10:12 AM, Dimitri DeFigueiredo <
[email protected]> wrote:
> Awesome haskellers,
>
> I am coding up a little function that aggregates "ask orders" in a
> currency exchange.
> Another way to look at it, is that the function takes as input a histogram
> or fdf (in list format) and outputs the cumulative distribution cdf (also
> in list format). So we are kind of "integrating" the input list.
>
> When given a list of asks in order of increasing price, the function
> returns a list of points in the graph of the total supply curve.
>
> Here's an example:
>
> asks: returned list:
>
> [ (Price 42, Volume 0.5), [ (Price 21, Volume 0.5),
> (Price 50, Volume 1 ), (Price 21+50=71, Volume 1.5),
> (Price 55, Volume 0.2)] (Price 21+50+11=82,Volume 1.7)]
>
> the returned list gives us the total supply curve (price = y-axis,
> quantity/volume = x-axis, so the order is flipped)
>
> Summarizing
>
> * We're adding up the volumes. The last volume on the list is the total
> volume available for sale.
> * We calculate the total amount to be paid to buy the current volume (for
> each item in the list).
>
> I have written up a simple function to do this:
>
> aggregate :: Num a => [(a,a)] -> [(a,a)]
> aggregate xs = aggregate' 0 0 xs
>
> aggregate' :: Num a => a -> a -> [(a,a)] -> [(a,a)]
> aggregate' _ _ [] = []
> aggregate' accX accY ((x,y):ls) = let accX' = accX + x * y
> accY' = accY + y
>
> in (accX',accY') : aggregate' accX'
> accY' ls
>
>
> main = print $ aggregate [(42,0.5),(50,1),(55,0.2)]
>
> However, this does not look very good to me and it feels like I'm
> reinventing the wheel.
>
> Question: Is there a better Haskell way to do this? I'm really anal about
> making it easy to read.
>
> Thanks!
>
> Dimitri
> _______________________________________________
> 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/20140521/65f10711/attachment-0001.html>
------------------------------
Message: 4
Date: Tue, 20 May 2014 23:07:46 -0400
From: David McBride <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] A better way to "integrate"
Message-ID:
<can+tr42gmytn8v_7om2eqm1luduxsvrquc9cq7jafz6pmbh...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Though I'm late to the party I might as well post what I have. Anyways
yeah foldr/foldl is the answer when you find yourself iterating over a list
with an accumulator.
aggregate :: [(Price,Volume)] -> [(Price, Volume)]
aggregate = reverse . snd . foldl' proc ((0,0),[])
where
proc ((!totalp,!totalv),sofar) (Price !p,Volume !v) =
let adjustedprice = round (fromIntegral p * v)
in ((adjustedprice+totalp,v+totalv), ((Price $ adjustedprice +
totalp, Volume $ v+totalv) : sofar))
Just make sure you use foldl' instead of foldl for performance reasons.
And also try to prepend to lists whenever possible and then reverse if you
need to.
On Tue, May 20, 2014 at 10:12 PM, Dimitri DeFigueiredo <
[email protected]> wrote:
> Awesome haskellers,
>
> I am coding up a little function that aggregates "ask orders" in a
> currency exchange.
> Another way to look at it, is that the function takes as input a histogram
> or fdf (in list format) and outputs the cumulative distribution cdf (also
> in list format). So we are kind of "integrating" the input list.
>
> When given a list of asks in order of increasing price, the function
> returns a list of points in the graph of the total supply curve.
>
> Here's an example:
>
> asks: returned list:
>
> [ (Price 42, Volume 0.5), [ (Price 21, Volume 0.5),
> (Price 50, Volume 1 ), (Price 21+50=71, Volume 1.5),
> (Price 55, Volume 0.2)] (Price 21+50+11=82,Volume 1.7)]
>
> the returned list gives us the total supply curve (price = y-axis,
> quantity/volume = x-axis, so the order is flipped)
>
> Summarizing
>
> * We're adding up the volumes. The last volume on the list is the total
> volume available for sale.
> * We calculate the total amount to be paid to buy the current volume (for
> each item in the list).
>
> I have written up a simple function to do this:
>
> aggregate :: Num a => [(a,a)] -> [(a,a)]
> aggregate xs = aggregate' 0 0 xs
>
> aggregate' :: Num a => a -> a -> [(a,a)] -> [(a,a)]
> aggregate' _ _ [] = []
> aggregate' accX accY ((x,y):ls) = let accX' = accX + x * y
> accY' = accY + y
>
> in (accX',accY') : aggregate' accX'
> accY' ls
>
>
> main = print $ aggregate [(42,0.5),(50,1),(55,0.2)]
>
> However, this does not look very good to me and it feels like I'm
> reinventing the wheel.
>
> Question: Is there a better Haskell way to do this? I'm really anal about
> making it easy to read.
>
> Thanks!
>
> Dimitri
> _______________________________________________
> 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/20140520/1157071a/attachment-0001.html>
------------------------------
Message: 5
Date: Wed, 21 May 2014 13:42:52 +0800
From: "yang.zhao" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Haskell network sample
Message-ID:
<cakxgz3aboxnxfb7vmja3jncgnqxaawofdpftnocrq5b4m3+...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
hi guys,
I'm newbie, just begin to learn Haskell.
now i write a very simple server and client .
Server:
import Control.Concurrent
import System.IO
import Network
port :: Int
port = 1234
main :: IO ()
main = withSocketsDo $ do
s <- listenOn $ PortNumber $ fromIntegral port
(h, _, _) <- accept s
sline <- hGetLine h
hPutStrLn h sline
putStrLn $ "send "++sline
threadDelay 1000000
hClose h
sClose s
Client :
import System.IO
import Network
port :: Int
port = 1234
main :: IO ()
main = withSocketsDo $ do
h <- connectTo "localhost" $ PortNumber $ fromIntegral port
hPutStrLn h "hello"
bs <- hGetContents h
putStrLn bs
hClose h
And, it doesn't work now . I run ./serv , then run ./cli , they will block
all the time.
but, when i run ./serv, and telnet localhost 1234 in another terminal, it
works fine.
so i don't know what's the wrong with my code.
anybody can tell me about my problem?
os is Debian 7, haskell-platform 2012.2.0.0
thanks a lot!!!
--
K.I.S.S.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20140521/8eeb30be/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 71, Issue 21
*****************************************