Send Beginners mailing list submissions to
        beginners@haskell.org

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
        beginners-requ...@haskell.org

You can reach the person managing the list at
        beginners-ow...@haskell.org

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


Today's Topics:

   1. Re:  How to unnest "do" (Daniel Trstenjak)
   2.  reorganizing lists (Bryce Verdier)
   3. Re:  reorganizing lists (Ozgur Akgun)
   4. Re:  reorganizing lists (divyanshu ranjan)
   5. Re:  reorganizing lists (Bryce Verdier)
   6. Re:  reorganizing lists (Brent Yorgey)
   7. Re:  reorganizing lists (Martin Drautzburg)
   8.  How to interact with a process (Martin Drautzburg)


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

Message: 1
Date: Mon, 28 Jan 2013 15:27:44 +0100
From: Daniel Trstenjak <daniel.trsten...@gmail.com>
Subject: Re: [Haskell-beginners] How to unnest "do"
To: beginners@haskell.org
Message-ID: <20130128142744.GA16791@machine>
Content-Type: text/plain; charset=us-ascii


Hi Emmanuel,

On Sun, Jan 27, 2013 at 09:46:30PM +0100, Emmanuel Touzery wrote:
> Thank you. I thought it might be, but it isn't exactly intuitive for me at
> this point. I'll read some more about that monad.

Sometimes it's hard to tell if Haskell is the most beautiful language
or the most abstract nonsense. ;)


Let's look at the Monad instance for the function (r -> a):

instance Monad ((->) r) where
   -- return :: a -> (r -> a)
   return a = \_ -> a

   -- (>>=) :: (r -> a) -> (a -> r -> b) -> (r -> b)
   left >>= right = \r -> right (left r) r 


'return' creates a function ignoring its argument and just returning 'a'.

'>>=' creates a function with the argument 'r'. The function 'left' is
called with 'r' and the function 'right' is called with the result of
'left' and 'r'.


Now let's look at the 'sequence' function:

sequence ms = foldr k (return []) ms
   where
      k m ms = do
         x  <- m
         xs <- ms
         return (x : xs)


It's easier to see what happens if we rewrite 'k':

k m ms = m >>= (\x -> (ms >>= \xs -> return (x : xs)))


We saw that '>>=' creates a function with one argument, that argument
is the String containing the file contents, 'x' is the return value
of one "sequenced" function which is combined (:) with the previous
ones.

At the end we have the function (String -> [String]).


Greetings,
Daniel



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

Message: 2
Date: Mon, 28 Jan 2013 10:37:53 -0800
From: Bryce Verdier <bryceverd...@gmail.com>
Subject: [Haskell-beginners] reorganizing lists
To: beginners@haskell.org
Message-ID: <5106c581.1050...@gmail.com>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hi All,

At the moment I have a list of lists. The inner list is a coordinate, 
like (x,y) but is [x,y] instead. What I would like to do is group all 
the x's into one list, and the y's into another. I know I can do this 
with calling 2 maps on the container, but I would also like to do this 
in one iteration.

Does anyone have any ideas?

Thanks in advance,
Bryce





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

Message: 3
Date: Mon, 28 Jan 2013 18:42:58 +0000
From: Ozgur Akgun <ozgurak...@gmail.com>
Subject: Re: [Haskell-beginners] reorganizing lists
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Message-ID:
        <calzazparl9ei5ce_ettvn+2xi9urlwuchmyp11brlza6gvj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,

On 28 January 2013 18:37, Bryce Verdier <bryceverd...@gmail.com> wrote:

> I know I can do this with calling 2 maps on the container, but I would
> also like to do this in one iteration.


As a learning experience, may I suggest you post the code you would have
written with two maps? Then we can try and improve on that to have only one
map.

Best,


-- 
Ozgur Akgun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130128/f234f5e8/attachment-0001.htm>

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

Message: 4
Date: Tue, 29 Jan 2013 00:14:18 +0530
From: divyanshu ranjan <idivyanshu.ran...@gmail.com>
Subject: Re: [Haskell-beginners] reorganizing lists
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <beginners@haskell.org>
Message-ID:
        <CAL9hw24QC5hJZcPoJdXv=fklaqadu664_u3ey_przf95meb...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

Hi,
  You can use foldl (\(fx, fy) [x,y] -> (x:fx, y:fy)) ([],[])

Thanks
Divyanshu Ranjan

On Tue, Jan 29, 2013 at 12:07 AM, Bryce Verdier <bryceverd...@gmail.com>wrote:

> Hi All,
>
> At the moment I have a list of lists. The inner list is a coordinate, like
> (x,y) but is [x,y] instead. What I would like to do is group all the x's
> into one list, and the y's into another. I know I can do this with calling
> 2 maps on the container, but I would also like to do this in one iteration.
>
> Does anyone have any ideas?
>
> Thanks in advance,
> Bryce
>
>
>
> ______________________________**_________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/**mailman/listinfo/beginners<http://www.haskell.org/mailman/listinfo/beginners>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130129/61593332/attachment-0001.htm>

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

Message: 5
Date: Mon, 28 Jan 2013 11:11:48 -0800
From: Bryce Verdier <bryceverd...@gmail.com>
Subject: Re: [Haskell-beginners] reorganizing lists
To: beginners@haskell.org
Message-ID: <5106cd74.5060...@gmail.com>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"

So I have a text full of x and y coordinates in the for x_y new line 
delimited. Here is the first 3 lines:
68_1
153_16099247764943158
153_775041589

I'm massaging the data to run a liner regression on it. At the moment 
the program I'm writing looks like this (still a work in progress...):

module Main where

import qualified Data.Text as T
import qualified Data.Text.IO as TI
import Numeric.GSL.Fitting.Linear
import Data.Packed.Vector

buildList :: IO [[T.Text]]
buildList = TI.readFile "lin_reg_data.txt" >>= return . map (T.split 
(=='_')) . T.lines

--main :: IO ()
--main = do
--    values <- buildList
--    let heads = fromList $ map (\x -> read (T.unpack . head $ x):: 
Double) values
--    let lasts = fromList $ map (\x -> read (T.unpack . last $ x):: 
Double) values
--    print linear heads lasts


I'm just trying to find a way to not iterate over "vaues" twice as that 
seems like a waste of computing time to me. Of course any advice on this 
would be appreciated.

Bryce


On 01/28/2013 10:42 AM, Ozgur Akgun wrote:
> Hi,
>
> On 28 January 2013 18:37, Bryce Verdier <bryceverd...@gmail.com 
> <mailto:bryceverd...@gmail.com>> wrote:
>
>     I know I can do this with calling 2 maps on the container, but I
>     would also like to do this in one iteration.
>
>
> As a learning experience, may I suggest you post the code you would 
> have written with two maps? Then we can try and improve on that to 
> have only one map.
>
> Best,
>
>
> -- 
> Ozgur Akgun
>
>
> _______________________________________________
> Beginners mailing list
> Beginners@haskell.org
> http://www.haskell.org/mailman/listinfo/beginners

-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20130128/b69ace12/attachment-0001.htm>

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

Message: 6
Date: Mon, 28 Jan 2013 14:24:37 -0500
From: Brent Yorgey <byor...@seas.upenn.edu>
Subject: Re: [Haskell-beginners] reorganizing lists
To: beginners@haskell.org
Message-ID: <20130128192437.ga12...@seas.upenn.edu>
Content-Type: text/plain; charset=us-ascii

On Mon, Jan 28, 2013 at 10:37:53AM -0800, Bryce Verdier wrote:
> Hi All,
> 
> At the moment I have a list of lists. The inner list is a coordinate,
> like (x,y) but is [x,y] instead. What I would like to do is group all
> the x's into one list, and the y's into another. I know I can do this
> with calling 2 maps on the container, but I would also like to do
> this in one iteration.

This can be done using the 'transpose' function from Data.List.

-Brent



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

Message: 7
Date: Mon, 28 Jan 2013 20:32:58 +0100
From: Martin Drautzburg <martin.drautzb...@web.de>
Subject: Re: [Haskell-beginners] reorganizing lists
To: beginners@haskell.org
Message-ID: <201301282032.59024.martin.drautzb...@web.de>
Content-Type: Text/Plain;  charset="iso-8859-1"

On Monday, 28. January 2013 19:37:53 Bryce Verdier wrote:
> Hi All,
> 
> At the moment I have a list of lists. The inner list is a coordinate,
> like (x,y) but is [x,y] instead. What I would like to do is group all
> the x's into one list, and the y's into another. I know I can do this
> with calling 2 maps on the container, but I would also like to do this
> in one iteration.

Something like this?
        groupMe  = foldl (\[rx,ry] [x,y] -> [x:rx,y:ry]) [[],[]] 


*Main> groupMe [[1,2],[1,3],[2,3]]
[[2,1,1],[3,3,2]]
-- 
Martin



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

Message: 8
Date: Mon, 28 Jan 2013 20:36:48 +0100
From: Martin Drautzburg <martin.drautzb...@web.de>
Subject: [Haskell-beginners] How to interact with a process
To: beginners@haskell.org
Message-ID: <201301282036.48458.martin.drautzb...@web.de>
Content-Type: text/plain;  charset="us-ascii"

Hello all,

I know how to play a Midi file. I also know how to read the keyboard. But I 
don't know how to bring the two together such that I can start and stop 
playing from the keyboard.

It is not required (just nice to have) that the console remains responsive 
while the midi file plays. But it is essential that I can stop the 
performance.

Is this difficult?
-- 
Martin



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

_______________________________________________
Beginners mailing list
Beginners@haskell.org
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 55, Issue 32
*****************************************

Reply via email to