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.  A question about network programming (Raphael P?bst)
   2. Re:  A question about network programming (Ertugrul Soeylemez)
   3. Re:  A question about network programming (Ertugrul Soeylemez)
   4. Re:  A question about network programming (Raphael P?bst)
   5. Re:  A question about network programming (aditya siram)
   6. Re:  A question about network programming (Raphael P?bst)
   7. Re:  A question about network programming (Sean Perry)
   8.  translations PCF to LC, reduction (ahrens)
   9.  How are complex Errors implemented (Christopher Howard)
  10. Re:  How are complex Errors implemented (Brandon Allbery)


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

Message: 1
Date: Wed, 8 Jun 2011 13:29:29 +0200
From: Raphael P?bst <[email protected]>
Subject: [Haskell-beginners] A question about network programming
To: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hey all!
This is probably a question that shows my incompetence more than
anything else, but I'm stuck with some TCP programming.

I have some code that looks like this:

hdl <- open TCP connection
message <- hGetContents hdl
answer <- do stuff with message
hPut hdl answer
hClose hdl

My problem is that the stuff that gets done with message happens, but
only after I close the connection rom the client's side and then of
course it is too late to get the answer out of said connection.

What am I doing wrong?

Many Thanks

Raf



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

Message: 2
Date: Wed, 8 Jun 2011 14:56:45 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: Re: [Haskell-beginners] A question about network programming
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

Raphael P?bst <[email protected]> wrote:

> This is probably a question that shows my incompetence more than
> anything else, but I'm stuck with some TCP programming.
>
> I have some code that looks like this:
>
> hdl <- open TCP connection
> message <- hGetContents hdl
> answer <- do stuff with message
> hPut hdl answer
> hClose hdl
>
> My problem is that the stuff that gets done with message happens, but
> only after I close the connection rom the client's side and then of
> course it is too late to get the answer out of said connection.
>
> What am I doing wrong?

You are using lazy I/O, which is in general unpredictable.  You have
almost no control over when the handle is closed.  If you want
predictable yet elegant I/O, I recommend an iteratee-based approach.
There is a nice online tutorial in the Yesod book [1].

[1] http://www.yesodweb.com/book/enumerator

BTW, I like your "hab dich lieb" handle. =P


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/





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

Message: 3
Date: Wed, 8 Jun 2011 14:59:56 +0200
From: Ertugrul Soeylemez <[email protected]>
Subject: Re: [Haskell-beginners] A question about network programming
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

Raphael P?bst <[email protected]> wrote:

> answer <- do stuff with message

As a side note, if you want to keep your lazy I/O approach, you should
make sure that "do stuff with message" does not force the entire list.


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/





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

Message: 4
Date: Wed, 8 Jun 2011 15:12:51 +0200
From: Raphael P?bst <[email protected]>
Subject: Re: [Haskell-beginners] A question about network programming
To: Ertugrul Soeylemez <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I will look into that. My main problem is not the fact that stuff gets
done after I close the handle on the client side, but that I need the
answer on the clientside. Is there any way to achieve this?

On 6/8/11, Ertugrul Soeylemez <[email protected]> wrote:
> Raphael P?bst <[email protected]> wrote:
>
>> answer <- do stuff with message
>
> As a side note, if you want to keep your lazy I/O approach, you should
> make sure that "do stuff with message" does not force the entire list.
>
>
> Greets,
> Ertugrul
>
>
> --
> nightmare = unsafePerformIO (getWrongWife >>= sex)
> http://ertes.de/
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



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

Message: 5
Date: Wed, 8 Jun 2011 08:13:16 -0500
From: aditya siram <[email protected]>
Subject: Re: [Haskell-beginners] A question about network programming
To: Raphael P?bst <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hi Raf,
I found that following the template for servers in the Network
Programming chapter [1] of Real World Haskell is the best way to go.
Scroll down to the "TCP Syslog Server" section for the relevant
information.
-deech

[1] http://book.realworldhaskell.org/read/sockets-and-syslog.html

On Wed, Jun 8, 2011 at 6:29 AM, Raphael P?bst
<[email protected]> wrote:
> Hey all!
> This is probably a question that shows my incompetence more than
> anything else, but I'm stuck with some TCP programming.
>
> I have some code that looks like this:
>
> hdl <- open TCP connection
> message <- hGetContents hdl
> answer <- do stuff with message
> hPut hdl answer
> hClose hdl
>
> My problem is that the stuff that gets done with message happens, but
> only after I close the connection rom the client's side and then of
> course it is too late to get the answer out of said connection.
>
> What am I doing wrong?
>
> Many Thanks
>
> Raf
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>



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

Message: 6
Date: Wed, 8 Jun 2011 15:17:13 +0200
From: Raphael P?bst <[email protected]>
Subject: Re: [Haskell-beginners] A question about network programming
To: aditya siram <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

Hey, that's what I did, pretty much.
I had to inflict some changes on the server though.

I'll play around with it some more and see what happens.

Raf

On 6/8/11, aditya siram <[email protected]> wrote:
> Hi Raf,
> I found that following the template for servers in the Network
> Programming chapter [1] of Real World Haskell is the best way to go.
> Scroll down to the "TCP Syslog Server" section for the relevant
> information.
> -deech
>
> [1] http://book.realworldhaskell.org/read/sockets-and-syslog.html
>
> On Wed, Jun 8, 2011 at 6:29 AM, Raphael P?bst
> <[email protected]> wrote:
>> Hey all!
>> This is probably a question that shows my incompetence more than
>> anything else, but I'm stuck with some TCP programming.
>>
>> I have some code that looks like this:
>>
>> hdl <- open TCP connection
>> message <- hGetContents hdl
>> answer <- do stuff with message
>> hPut hdl answer
>> hClose hdl
>>
>> My problem is that the stuff that gets done with message happens, but
>> only after I close the connection rom the client's side and then of
>> course it is too late to get the answer out of said connection.
>>
>> What am I doing wrong?
>>
>> Many Thanks
>>
>> Raf
>>
>> _______________________________________________
>> Beginners mailing list
>> [email protected]
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>



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

Message: 7
Date: Wed, 8 Jun 2011 08:00:18 -0700
From: Sean Perry <[email protected]>
Subject: Re: [Haskell-beginners] A question about network programming
To: Raphael P?bst <[email protected]>
Cc: beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain;       charset=utf-8

Note they set the buffering to line buffered. This way you get data in line 
based chunks instead of all at once.

You could replace the sock IO with strip and see the difference interactively.

On Jun 8, 2011, at 6:17, Raphael P?bst <[email protected]> wrote:

> Hey, that's what I did, pretty much.
> I had to inflict some changes on the server though.
> 
> I'll play around with it some more and see what happens.
> 
> Raf
> 
> On 6/8/11, aditya siram <[email protected]> wrote:
>> Hi Raf,
>> I found that following the template for servers in the Network
>> Programming chapter [1] of Real World Haskell is the best way to go.
>> Scroll down to the "TCP Syslog Server" section for the relevant
>> information.
>> -deech
>> 
>> [1] http://book.realworldhaskell.org/read/sockets-and-syslog.html
>> 
>> On Wed, Jun 8, 2011 at 6:29 AM, Raphael P?bst
>> <[email protected]> wrote:
>>> Hey all!
>>> This is probably a question that shows my incompetence more than
>>> anything else, but I'm stuck with some TCP programming.
>>> 
>>> I have some code that looks like this:
>>> 
>>> hdl <- open TCP connection
>>> message <- hGetContents hdl
>>> answer <- do stuff with message
>>> hPut hdl answer
>>> hClose hdl
>>> 
>>> My problem is that the stuff that gets done with message happens, but
>>> only after I close the connection rom the client's side and then of
>>> course it is too late to get the answer out of said connection.
>>> 
>>> What am I doing wrong?
>>> 
>>> Many Thanks
>>> 
>>> Raf
>>> 
>>> _______________________________________________
>>> Beginners mailing list
>>> [email protected]
>>> http://www.haskell.org/mailman/listinfo/beginners
>>> 
>> 
> 
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners



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

Message: 8
Date: Wed, 08 Jun 2011 18:34:04 +0200
From: ahrens <[email protected]>
Subject: [Haskell-beginners] translations PCF to LC, reduction
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

Hello,

sorry for this slightly offtopic post:

I am looking for information about translations from the programming 
language PCF to the pure lambda calculus. I am particularly interested 
in how those translations behave with respect to reduction in the source 
and target languages, such as

- does a specific translation create new redexes?
- are irreducible terms mapped to irreducibles?

I'd be grateful for any reference regarding possible translations.

Thanks,
ben



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

Message: 9
Date: Wed, 08 Jun 2011 08:45:18 -0800
From: Christopher Howard <[email protected]>
Subject: [Haskell-beginners] How are complex Errors implemented
To: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

So, I know from the source code at hackage that the IOException type is
implemented with multiple fields, like so:

data IOException
 = IOError {
     ioe_handle   :: Maybe Handle,   -- the handle used by the action
flagging
                                     -- the error.
     ioe_type     :: IOErrorType,    -- what it was.
     ioe_location :: String,         -- location.
     ioe_description :: String,      -- error type specific information.
     ioe_errno    :: Maybe CInt,     -- errno leading to this error, if any.
     ioe_filename :: Maybe FilePath  -- filename the error is related to.
   }
    deriving Typeable

However, the hackage docs for Control.Monad.Error indicates that there
is an Error IOException instance. But the Error class requires the
implementation of at least one of two functions, noMsg and strMsg, which
create an error with either a String or with nothing. Question: in the
implementation of Error IOException, how does noMsg or strMsg create new
IOExceptions when they don't take all the required information? (I
couldn't find the implementation in the source code by clicking the
"source" buttons on the page... maybe somebody could post that.)

Reason I ask: Lets say I want to create my own error type which is a
member of Error, but has multiple record fields. How would I implement
noMsg and strMsg?

-- 
frigidcode.com
theologia.indicium.us



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

Message: 10
Date: Wed, 8 Jun 2011 12:52:39 -0400
From: Brandon Allbery <[email protected]>
Subject: Re: [Haskell-beginners] How are complex Errors implemented
To: Christopher Howard <[email protected]>
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8

On Wed, Jun 8, 2011 at 12:45, Christopher Howard
<[email protected]> wrote:
> Reason I ask: Lets say I want to create my own error type which is a
> member of Error, but has multiple record fields. How would I implement
> noMsg and strMsg?

However you want.  The thing to keep in mind is that those are the
required constructors, but need not be the *only* constructors; your
code would use other constructors that provide more information, while
noMsg and strMsg are used by generic code that wouldn't know what to
do with your additional fields anyway.  So pick saneish defaults.



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

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


End of Beginners Digest, Vol 36, Issue 23
*****************************************

Reply via email to