Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/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. Re: How to get IO String from Network.Socket.ByteString.recv
method (Steven Leiva)
----------------------------------------------------------------------
Message: 1
Date: Tue, 5 Jun 2018 14:05:00 -0500
From: Steven Leiva <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Cc: Dinesh Amerasekara <[email protected]>
Subject: Re: [Haskell-beginners] How to get IO String from
Network.Socket.ByteString.recv method
Message-ID:
<CA+=woS43kj_=kpc6b1szxjdjawbfqnzkfxmbgrfrqghxm-u...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
A bit late to the party, but to build on the previous answer, you're going
to run into the same problem with the Text data type, which has both a lazy
variant and a strict (?) variant.
The functions to convert from/to the strict/lazy variant are usually in the
lazy module:
*Data.Text.Lazy.toStrict* and *Data.Text.Lazy.fromStrict*.
*Data.ByteString.Lazy.toStrict* and *Data.ByteString.Lazy.toStrict*.
It's a common use-case to want to save the Text / ByteString to a file, and
in those cases you can find helper functions such as
*Data.ByteString.Lazy.writeFile*.
On Sun, May 20, 2018 at 6:56 PM, Daniel Bergey <[email protected]> wrote:
> Network.Socket.ByteString.recv uses the strict ByteString from
> Data.ByteString, not the lazy one from Data.ByteString.Lazy. So you
> want the `unpack` from Data.ByteString.Char8, rather than
> Data.ByteString.Lazy.Char8.
>
> I never remember which functions return strict or lazy ByteString. I
> find the easiest way to check is to open the online docs and see where
> the `ByteString` link points:
>
> https://hackage.haskell.org/package/network-2.7.0.0/docs/
> Network-Socket-ByteString.html#v:recv
>
> points to:
>
> https://hackage.haskell.org/package/bytestring-0.10.8.2/
> docs/Data-ByteString.html#t:ByteString
>
> hope this helps,
> bergey
>
> On 2018-05-20 at 07:52, Dinesh Amerasekara <[email protected]> wrote:
> > Hi,
> >
> > I am unable to compile the below code.
> >
> > import Network.Socket hiding(recv)
> > import Network.Socket.ByteString as S (recv)
> > import qualified Data.ByteString.Lazy.Char8 as Char8
> >
> > getMessage :: Socket -> IO String
> > getMessage sock = Char8.unpack <$> S.recv sock 8888
> >
> > It gives the below error.
> >
> > Couldn't match type ‘Data.ByteString.Internal.ByteString’
> > with ‘ByteString’
> > NB: ‘ByteString’ is defined in ‘Data.ByteString.Lazy.Internal’
> > ‘Data.ByteString.Internal.ByteString’
> > is defined in ‘Data.ByteString.Internal’
> > Expected type: IO ByteString
> > Actual type: IO Data.ByteString.Internal.ByteString
> >
> > In the second argument of ‘(<$>)’, namely ‘recv sock 8888’
> > In the expression: unpack <$> recv sock 8888
> > In an equation for ‘getMsg’:
> > getMsg sock = unpack <$> recv sock 8888
> >
> > Can somebody tell me how I can return the IO String using
> > Network.Socket.ByteString.recv?
> >
> > Best Regards,
> > Dinesh.
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
--
Steven Leiva
305.528.6038
[email protected]
http://www.linkedin.com/in/stevenleiva
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180605/b19da434/attachment-0001.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 120, Issue 4
*****************************************