[Haskell-cafe] Re: Network.Socket Woes

2008-03-07 Thread Benedikt Schmidt
Adam Langley [EMAIL PROTECTED] writes:

 On Fri, Mar 7, 2008 at 8:10 AM, Scott Bell [EMAIL PROTECTED] wrote:
  my test program. The Haskell version, however, does not
  return from recvFrom. I've also tried wrapping this in a
  withSocketsDo, with no effect.

 So this is a long standing, ah, issue with the Network modules.

 Try sending a UDP packet to port 45607 and you'll find that the
 Haskell code gets it.

 hex(45607) = 0xb227
 0x27b2 = 10162

 In short, PortNum doesn't do the endian conversion for you. And I
 don't know a good way to figure out the endianness of the underlying
 system from Haskell I'm afraid. I usually end up FFIing out to htons
 or just assuming that the system is little-endian.

The PortNumber type is an instance of Num, so it works  if you do not
use the PortNum constructor.

Prelude Network.Socket case 10162 :: PortNumber of PortNum p - p
45607

Benedikt

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


Re: [Haskell-cafe] Re: Network.Socket Woes

2008-03-07 Thread Adam Langley
On Fri, Mar 7, 2008 at 11:04 AM, Benedikt Schmidt [EMAIL PROTECTED] wrote:
  The PortNumber type is an instance of Num, so it works  if you do not
  use the PortNum constructor.

  Prelude Network.Socket case 10162 :: PortNumber of PortNum p - p
  45607

And there was the trick that I've been missing all this time ;) I'll
probably submit a documentation patch for this since I'm a Bear of
Little Brain and this wasn't obvious to me.

-- 
Adam Langley [EMAIL PROTECTED] http://www.imperialviolet.org
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Re: Network.Socket Woes

2008-03-07 Thread Donn Cave


On Mar 7, 2008, at 11:46 AM, Adam Langley wrote:



And there was the trick that I've been missing all this time ;) I'll
probably submit a documentation patch for this since I'm a Bear of
Little Brain and this wasn't obvious to me.


That would be great - I have been doing the same thing, and was
just a minute short of sending in the FORTRAN Programmer's solution.
It would have really made your eyes burn.

Donn Cave, [EMAIL PROTECTED]

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


Re: [Haskell-cafe] Re: Network.Socket Woes

2008-03-07 Thread Felipe Lessa
On Fri, Mar 7, 2008 at 4:04 PM, Benedikt Schmidt [EMAIL PROTECTED] wrote:
  The PortNumber type is an instance of Num, so it works  if you do not
  use the PortNum constructor.

  Prelude Network.Socket case 10162 :: PortNumber of PortNum p - p
  45607

Considering that PortNumber implements toEnum/fromEnum, why is PortNum
exported anyway?

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