It looks like the easiest way to get "optional parameters" in Haskell would 
be to change the type from `Int` to `Maybe Int` and then to use `fromMaybe`:

fromSocket
  :: MonadIO m
  => Socket     -- ^Connected socket.
  -> Maybe Int  -- ^Maximum number of bytes to receive and send
                -- dowstream at once. Any positive value is fine, the
                -- optimal value depends on how you deal with the
                -- received data. Try using @4096@ if you don't care.
  -> Producer' B.ByteString m ()
fromSocket sock nbytes = loop where
    loop = do
        bs <- liftIO (NSB.recv sock $ fromMaybe 4096 nbytes)
        if B.null bs
           then return ()
           else yield bs >> loop
{-# INLINABLE fromSocket #-}


Is this sensible enough for a pull request ?

Of course I would need to do the same for `fromSocketTimeout`

There is this other trick but I find it too complex for the use case at 
hand:

http://byorgey.wordpress.com/2010/04/03/haskell-anti-pattern-incremental-ad-hoc-parameter-abstraction/

Does Conduit on the other hand set this params to 4096 ?
https://github.com/snoyberg/conduit/blob/571f37a95606e7a22b04c47bae791ada8314ff45/network-conduit/Data/Conduit/Network.hs#L87


On Monday, March 10, 2014 8:30:12 AM UTC+1, Pierre R wrote:
>
> Thanks !
>
> I have found the second Int params of `fromSocket` to be quite confusing 
> (as it is set to the same value as the port)
>
>
> https://github.com/michaelt/pipes-network-tcp-examples/blob/master/server_toupper.hs#L7
>
> This makes me wonder why `fromSocket` does not provide sensible defaults 
> in the first place. I mean the comment "Try using 4096 if you don't care" 
> sounds kind of awkward to me.
>
> I have a feeling that Haskell is a pain in this kind of area (because of 
> the lack of what is called "method overloading" in some  well-known OO 
> languages).
>
> Cheers,
>
> On Monday, March 10, 2014 3:31:24 AM UTC+1, Michael Thompson wrote:
>>
>> It's nothing to write home, or even to the list, about -- but not having 
>> used
>> `pipes-network`, I rewrote the super-elementary examples in Michael S's 
>> post http://www.yesodweb.com/blog/2014/03/network-conduit-async in 
>> pipe-ese.
>> I think partly I just wanted to see if the pipes versions would seem
>> handsomer and more intelligible. 
>>
>> The reddit discussion (and my experience) suggested that 
>> Michael was not wrong to think that such elementary 
>> examples might have a good tutorial purpose. Since I don't 
>> particularly mind seeming or even being simple-minded, it occurred 
>> to me, having finished the little exercise, that I might as well link 
>> them here. 
>>
>> https://github.com/michaelt/pipes-network-tcp-examples
>>
>> That I could use a graded series of examples beginning
>> from about where these leave of  will perhaps be clear. 
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Haskell Pipes" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].

Reply via email to