[Haskell-cafe] What is the surefire way to handle all exceptions and make sure the program doesn't fail?

2012-07-16 Thread Yifan Yu
First of all, apologise if the question is too broad. The background goes
like this: I've implemented a server program in Haskell for my company
intended to replace the previous one written in C which crashes a lot (and
btw the technology of the company is exclusively C-based).  When I chose
Haskell I promised my manager (arrogantly - I actually made a bet with
him), "it won't crash". Now it has been finished (with just a few hundred
LOC), and my test shows that it is indeed very stable. But by looking at
the code again I'm a little worried, since I'm rather new to exception
handling and there're many networking-related functions in the program. I
was tempted to catch (SomeException e) at the very top-level of the program
and try to recursively call main to restart the server in case of any
exception being thrown, but I highly doubt that is the correct and
idiomatic way. There are also a number of long-running threads launched
from the main thread, and exceptions thrown from these threads can't be
caught by the top-level `catch' in the main thread. My main function looks
like this:

main :: IO ()
main = withSocketsDo $ do
sCameraU <- socketNewPassive False 6000
sStunU   <- socketNewPassive False 3478
sCmdT<- socketNewPassive True  7000
mvarCam  <- newMVar M.empty
mvarLog  <- newMVar []

forkIO $ regCamera sCameraU mvarCam mvarLog
forkIO $ updCamera mvarCam mvarLog
forkIO $ stun sCameraU sStunU mvarCam mvarLog

listen sCmdT 128
processCmd sCmdT mvarCam mvarLog

sClose sCameraU
sClose sStunU
sClose sCmdT

I find that I can't tell whether a function will throw any exception at
all, or what exceptions will be thrown, by looking at their documentation.
I can only tell if I browse the source code. So the question is, how can I
determine all the exceptions that can be thrown by a given function? And
what is the best way to handle situations like this, with both the
long-running threads and main thread need to be restarted whenever
exceptions happen.

Regards,
Yifan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Call to arms: lambda-case is stuck and needs your help

2012-07-16 Thread Mikhail Vorozhtsov
Good news everyone. LambdaCase and MultiWayIf are now in HEAD. Thanks
for participating in the final push!

On Thu, Jul 5, 2012 at 9:42 PM, Mikhail Vorozhtsov
 wrote:
>
> Hi.
>
> After 21 months of occasional arguing the lambda-case proposal(s) is in 
> danger of being buried under its own trac ticket comments. We need fresh 
> blood to finally reach an agreement on the syntax. Read the wiki page[1], 
> take a look at the ticket[2], vote and comment on the proposals!
>
> P.S. I'm CC-ing Cafe to attract more people, but please keep the discussion 
> to the GHC Users list.
>
> [1] http://hackage.haskell.org/trac/ghc/wiki/LambdasVsPatternMatching
> [2] http://hackage.haskell.org/trac/ghc/ticket/4359

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is the difference between runhaskell and compile?

2012-07-16 Thread Magicloud Magiclouds
Sorry for that. The problem got solved yesterday.

On Mon, Jul 16, 2012 at 6:01 PM, Lars Viklund  wrote:
> On Thu, Jul 12, 2012 at 09:41:43AM +0800, Magicloud Magiclouds wrote:
>> Sorry for the attachments. They are wireshark files.
>
> May I suggest not sending multi-megabyte files of limited interest down
> a widely subscribed list? Contrary to popular belief, bandwidth, time
> and spool storage isn't free.
>
> It might be a very good idea to take those off-list.
>
> --
> Lars Viklund | z...@acc.umu.se
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



-- 
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Adding to the haskell wiki

2012-07-16 Thread Simon Michael

Hi Nathan,

cool. You should get your blog added to http://planet.haskell.org/ , see instructions there. And if you think wiki links 
are needed, the games development page(s) could be a good place.


Looking forward to reading,
-Simon


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Adding to the haskell wiki

2012-07-16 Thread Brent Yorgey
On Mon, Jul 16, 2012 at 02:00:46PM +0200, Nathan Hüsken wrote:
> Hey,
> 
> I have been a passive member of the haskell community for quite some
> time now. I have benefit from the community a lot through the mailing
> list, the haskell webpage and other channels. Thanks for all that!
> 
> Now I am trying to give a little bit back, and I started a blog about
> writing javascript games in haskell using UHC and haste.
> I am not an expert in haskell nor javascript, but I am "collecting"
> information from various sources and put it together in the blog so that
> others with a similar goal my have a smoother start.
> 
> Writing a blog is one thing, but of course I also want people who are
> interested in the topic to find it.
> 
> Never being an active member of the community, I wonder if I should do.
> I guess I should add it to the haskellwiki. But I am unsure where.
> It certainly falls in the "games" category, but the page only lists game
> projects.
> 
> The blog can be found here: http://jshaskell.blogspot.de/

If you want people to find your blog, a better idea is to have it
added to the Planet Haskell blog aggregator. [1] Then write blog posts
which are interesting enough that people will post them to the Haskell
reddit.  I doubt putting a link to your blog on the Haskell wiki will
make much difference, though you are certainly welcome to of course.

[1] http://planet.haskell.org/

-Brent

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Haskell] A riddle...

2012-07-16 Thread Lyndon Maydwell
I'd guess that type-inference is allowing rgbliste to use Integers
when farbliste is commented out, but restricting it to 16 Bit types
when it is uncommented. I don't have the GTK module installed on this
machine, but try adding some type annotations to see if this is the
case.

The maxBound of Word16 appears to confirm my suspicion:

Prelude GHC.Word> maxBound :: Word16
65535

On Mon, Jul 16, 2012 at 11:36 PM, Vo Minh Thu  wrote:
> Oh the mailing list was haskell@ instead of café. Sorry. (Now cc'ing café.)
>
> Andreas, please post this kind of mail to the haskell-cafe instead of
> the haskell mailing list.
>
> 2012/7/16 Vo Minh Thu :
>> It seems like the infered type (and thus bounds) is different when you
>> force the result to be a Color or not. Just give explicit type
>> signatures and conversion functions.
>>
>> Cheers,
>> Thu
>>
>> 2012/7/16 Andreas Abel :
>>> Today a student came to me with a piece of code that worked it executed by
>>> itself, but produced different result in the context of his larger problem.
>>> We cut down the example to the following:
>>>
 import Graphics.UI.Gtk

 -- should produce [(26471,0,65535),...
 rgbliste =
  (map (\ i ->
   let rb = 5 * (mod (mod 181935629 (4534+i)) 100)-250+128 in
   let gb = 5 * (mod (mod 128872693 (5148+i)) 100)-250+128 in
   let bb = 5 * (mod (mod 140302469 (7578+i)) 100)-250+128 in
   let r = min 255 $ max 0 rb in
   let g = min 255 $ max 0 gb in
   let b = min 255 $ max 0 bb in
   (r*257,g*257,b*257)) [0..])

 --farbliste = map (\ (r,g,b) -> Color r g b) rgbliste

 main :: IO ()
 main = do
   print $ head rgbliste
>>>
>>>
>>> If you run it, it prints (26471,0,65535).
>>> If you uncomment the def. of farbliste, it prints (44461,65535,65535).
>>>
>>> I was surprised.  What is going on?
>>>
>>> Cheers,
>>> Andreas
>>>
>>> --
>>> Andreas Abel  <><  Du bist der geliebte Mensch.
>>>
>>> Theoretical Computer Science, University of Munich
>>> Oettingenstr. 67, D-80538 Munich, GERMANY
>>>
>>> andreas.a...@ifi.lmu.de
>>> http://www2.tcs.ifi.lmu.de/~abel/
>>>
>>>
>>> ___
>>> Haskell mailing list
>>> hask...@haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] [Haskell] A riddle...

2012-07-16 Thread Vo Minh Thu
Oh the mailing list was haskell@ instead of café. Sorry. (Now cc'ing café.)

Andreas, please post this kind of mail to the haskell-cafe instead of
the haskell mailing list.

2012/7/16 Vo Minh Thu :
> It seems like the infered type (and thus bounds) is different when you
> force the result to be a Color or not. Just give explicit type
> signatures and conversion functions.
>
> Cheers,
> Thu
>
> 2012/7/16 Andreas Abel :
>> Today a student came to me with a piece of code that worked it executed by
>> itself, but produced different result in the context of his larger problem.
>> We cut down the example to the following:
>>
>>> import Graphics.UI.Gtk
>>>
>>> -- should produce [(26471,0,65535),...
>>> rgbliste =
>>>  (map (\ i ->
>>>   let rb = 5 * (mod (mod 181935629 (4534+i)) 100)-250+128 in
>>>   let gb = 5 * (mod (mod 128872693 (5148+i)) 100)-250+128 in
>>>   let bb = 5 * (mod (mod 140302469 (7578+i)) 100)-250+128 in
>>>   let r = min 255 $ max 0 rb in
>>>   let g = min 255 $ max 0 gb in
>>>   let b = min 255 $ max 0 bb in
>>>   (r*257,g*257,b*257)) [0..])
>>>
>>> --farbliste = map (\ (r,g,b) -> Color r g b) rgbliste
>>>
>>> main :: IO ()
>>> main = do
>>>   print $ head rgbliste
>>
>>
>> If you run it, it prints (26471,0,65535).
>> If you uncomment the def. of farbliste, it prints (44461,65535,65535).
>>
>> I was surprised.  What is going on?
>>
>> Cheers,
>> Andreas
>>
>> --
>> Andreas Abel  <><  Du bist der geliebte Mensch.
>>
>> Theoretical Computer Science, University of Munich
>> Oettingenstr. 67, D-80538 Munich, GERMANY
>>
>> andreas.a...@ifi.lmu.de
>> http://www2.tcs.ifi.lmu.de/~abel/
>>
>>
>> ___
>> Haskell mailing list
>> hask...@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] lazy boxed array and builder?

2012-07-16 Thread Simon Meier
Hi Bas,

I'm not sure the unpacking is absolutely necessary. It might be worth
to give it a try with not-unpacked strict chunks. In some of my
ByteString builder experiments, I even got better performance by not
unpacking the ByteStrings in some of the intermediate data structures.
My gut feeling says that compensating the extra indirection is not too
hard provided you ensure that your chunks are large enough. The corner
case of having lots of small lazy bytestrings is likely to be slower.
Experiments will tell.

best regards,
Simon

2012/7/12 Bas van Dijk :
> On 12 July 2012 15:35, Yves Parès  wrote:
>> I remember this discussion, lazy vectors would also enable an implementation
>> of bytestring and (maybe) text only with unboxed vectors, unifying it all:
>> type ByteString = Vector Word8
>
> Yes, I would like to add a lazy storable vector to
> vector-bytestring[1] to make the API 100% consistent with bytestring.
>
> Ideally we would have a type like:
>
> data Lazy vector a = Empty | Chuck {-# UNPACK #-} !(vector a) (Lazy vector a)
>
> Unfortunately GHC can't unpack polymorphic fields. The next best thing
> is to use a type family which for each type of vector would return its
> lazy version (where the vector is unpacked in the cons cell). Then we
> would need a class for common operations on those lazy vectors.
>
> Regards,
>
> Bas
>
> [1] http://hackage.haskell.org/package/vector-bytestring
> https://github.com/basvandijk/vector-bytestring
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


[Haskell-cafe] Adding to the haskell wiki

2012-07-16 Thread Nathan Hüsken
Hey,

I have been a passive member of the haskell community for quite some
time now. I have benefit from the community a lot through the mailing
list, the haskell webpage and other channels. Thanks for all that!

Now I am trying to give a little bit back, and I started a blog about
writing javascript games in haskell using UHC and haste.
I am not an expert in haskell nor javascript, but I am "collecting"
information from various sources and put it together in the blog so that
others with a similar goal my have a smoother start.

Writing a blog is one thing, but of course I also want people who are
interested in the topic to find it.

Never being an active member of the community, I wonder if I should do.
I guess I should add it to the haskellwiki. But I am unsure where.
It certainly falls in the "games" category, but the page only lists game
projects.

The blog can be found here: http://jshaskell.blogspot.de/

Regards,
Nathan

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is the difference between runhaskell and compile?

2012-07-16 Thread Lars Viklund
On Thu, Jul 12, 2012 at 09:41:43AM +0800, Magicloud Magiclouds wrote:
> Sorry for the attachments. They are wireshark files.

May I suggest not sending multi-megabyte files of limited interest down
a widely subscribed list? Contrary to popular belief, bandwidth, time
and spool storage isn't free.

It might be a very good idea to take those off-list.

-- 
Lars Viklund | z...@acc.umu.se

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] What is the difference between runhaskell and compile?

2012-07-16 Thread Magicloud Magiclouds
Have found the place in openldap where the error occurs, but do not know why.
Please refer to http://hackage.haskell.org/trac/ghc/ticket/6128 .

On Thu, Jul 12, 2012 at 2:03 PM, Magicloud Magiclouds
 wrote:
> I made a little code, to explicitly use unbind:
> ldapWith :: String
>  -> LDAPInt
>  -> (LDAP -> IO a)
>  -> IO a
> ldapWith host port f =
>   withCString host $ \cs -> do
> cld <- cldap_init cs port
> ptr <- checkNULL "ldapWith" (return cld)
> rv <- newForeignPtr_ ptr
> ldapSetVersion3 cld
> a <- f rv
> _ <- cldap_unbind cld
> return a
>
> And it gave me another packet data. Sec 11 is runhaskell, Sec 15 is
> binary (failed). The failed one has a FIN, ACK, weird. LDAP-0.6.6 is a
> binding to c library without any other haskell library except base, I
> think how ghc works should not effect its internal network
> operation
>
> On Thu, Jul 12, 2012 at 10:14 AM, Magicloud Magiclouds
>  wrote:
>> Dug a little more. Seems that ghc 7.4.* finalizes (ldap_unbind action)
>> the ldap ptr before the references were actually dropped.
>>
>> On Thu, Jul 12, 2012 at 9:41 AM, Magicloud Magiclouds
>>  wrote:
>>> Sorry for the attachments. They are wireshark files.
>>>
>>> On Thu, Jul 12, 2012 at 9:35 AM, Magicloud Magiclouds
>>>  wrote:
 OK. Finally this problem totally prevents my project from working.
 By some guy's suggestion, I did a packet capturing, which really
 showed a difference.
 The rwdc file is for a ldap that at our IDC, which did not work with
 compiled binary. The rodc file is for a ldap that at local, which
 worked all the time. Each file contains two parts of records, at 3.*
 sec and 6/7.* sec. The 3.* part is for runhaskell way. The 6/7.* part
 is for compiled binary way.
 The big difference here is: the failed one sent unbindRequest before
 got bindResponse success.
 Just a clue, I have no idea what is going on

 On Fri, Jun 1, 2012 at 5:17 PM, Chris Dornan  wrote:
> No problem -- I have attached the executable too.
>
> Chris
>
> -Original Message-
> From: Magicloud Magiclouds [mailto:magicloud.magiclo...@gmail.com]
> Sent: 01 June 2012 02:01
> To: Chris Dornan
> Subject: Re: [Haskell-cafe] What is the difference between runhaskell and 
> compile?
>
> I see.
> Although I am using a UTF-8 environment, but all string I was using were 
> ASCIIs.
> If it is not too much trouble, may I have your LDAP compiled library 
> files? I think since the Main.o is identical, maybe the libraries are 
> different.
>
> On Thu, May 31, 2012 at 2:09 PM, Chris Dornan  
> wrote:
>> I wouldn't pay too much attention to the fact that the hash tags are
>> different -- they are very unlikely to be the same across two
>> installations. (For example, my GHC installations are relocated under
>> /usr/hs, immediately changing the contents of all of the .conf files
>> and therefore the hashes.)
>>
>> The object files are more interesting, and they are identical!
>>
>> At the moment I can only explain what we are seeing by assuming that 
>> some change has affected the GHC 7.4.1 runtime system -- but only for 
>> compiled programs.
>>
>> Are you using non-ASCII characters in your LDAP passwords? I am thinking 
>> that maybe the compiled 7.4.1 could be using a different LOCALE from 
>> everything else, leading in some way to the passwords being encoded 
>> differently en route to the LDAP server. I don't know whether this could 
>> actually happen, but it is the kind of mechanism that seem most likely 
>> to be causing the problem.
>>
>> Did you try to running the variants that read address, account and 
>> passwords from standard input? Did it show the same perverse behaviour?
>>
>> Chris
>>
>>
>>
>>
>>
>> -Original Message-
>> From: Magicloud Magiclouds [mailto:magicloud.magiclo...@gmail.com]
>> Sent: 31 May 2012 02:47
>> To: Chris Dornan
>> Subject: Re: [Haskell-cafe] What is the difference between runhaskell 
>> and compile?
>>
>> Hi,
>>  I have compared the files. The .o-es are exactly the same. The .hi-s 
>> are different.
>>  The interface hash, flag hash, and "import  -/ 
>> LDAP-0.6.6:LDAP.Constants x(hash)" are different.
>>  I do not know why only this module (LDAP.Constants) has a different 
>> hash. I am not quite familiar with ghc compiling process. May I know 
>> your conclusion?
>>
>> On Wed, May 30, 2012 at 3:50 PM, Chris Dornan  
>> wrote:
>>> Did you carry out a standard (optimised) build to get ghc-7.4.1?
>>>
>>> Are you going to try the justhub rpms or compare the object/header 
>>> files I sent.
>>>
>>> Chris
>>>
>>> -Original Message-
>>> From: Magicloud Magiclouds [mailto:magi