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 (Daniel Bergey)
2. Understanding type variables in Haskell class declarations
(PATRICK BROWNE)
3. Re: Understanding type variables in Haskell class
declarations (David McBride)
----------------------------------------------------------------------
Message: 1
Date: Sun, 20 May 2018 19:56:47 -0400
From: Daniel Bergey <[email protected]>
To: Dinesh Amerasekara <[email protected]>, [email protected]
Subject: Re: [Haskell-beginners] How to get IO String from
Network.Socket.ByteString.recv method
Message-ID:
<m07enxg9ts.fsf@Nusselt.local.i-did-not-set--mail-host-address--so-tickle-me>
Content-Type: text/plain; charset=utf-8
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
------------------------------
Message: 2
Date: Mon, 21 May 2018 11:20:53 +0100
From: PATRICK BROWNE <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Understanding type variables in Haskell
class declarations
Message-ID:
<cagflrkff4pjngn_2zm5vl+jjviduc9hdsez0gxovaz4qjqg...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I am trying to understand how to interpret type variables in Haskell class
declarations from a paper
<http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=1EA31D76684217BC728F916144BC6C38?doi=10.1.1.109.6853&rep=rep1&type=pdf>
.
With respect to the code below I have the following questions:
1. What is the difference between "a b" in the header of the Container
class and "a b" in the signature of the class methods? Does the whitespace
in header mean 2 distinct types and in the methods mean function
application?
2. In the Boathouse class what is the difference between the first ocurance
of "b p" and the second bracketed "(b p)"?
3. When I try to make instance of these classes I seem to need
FlexibleInstances. Why is this?
{-# LANGUAGE MultiParamTypeClasses #-}
-- Containers a b stands for all container types a holding things of type b.
-- from :info command a has kind *->*, b has kind *
class Containers a b where
insert :: b -> a b -> a b
remove :: b -> a b -> a b
whatsIn :: a b -> [b]
class Surfaces a b where
put :: b -> a b -> a b
takeOff :: b -> a b -> a b
whatsOn :: a b -> [b]
-- from :info command "p" has kind *, "h" and "b" have kind *->*
class People p
class Containers h p => Houses h p where
class (People p, Surfaces h p) => Boats h p where
class (Boats b p,Houses h (b p)) => BoatHouses h b p where
class (People p, Houses h (b p),Boats b p) => HouseBoats h b p
--
This email originated from DIT. If you received this email in error,
please delete it from your system. Please note that if you are not the
named addressee, disclosing, copying, distributing or taking any action
based on the contents of this email or attachments is prohibited.
www.dit.ie <http://www.dit.ie/>
Is ó ITBÁC
a tháinig an ríomhphost seo. Má
fuair tú an ríomhphost seo trí earráid, scrios
de do chóras é le do thoil.
Tabhair ar aird, mura tú an seolaí ainmnithe, go
bhfuil dianchosc ar aon
nochtadh, aon chóipeáil, aon dáileadh nó ar aon ghníomh
a dhéanfar bunaithe
ar an ábhar atá sa ríomhphost nó sna hiatáin seo. www.dit.ie
<http://www.dit.ie/>
Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is
on the move to Grangegorman <http://www.dit.ie/grangegorman>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180521/2da1646c/attachment-0001.html>
------------------------------
Message: 3
Date: Mon, 21 May 2018 08:31:33 -0400
From: David McBride <[email protected]>
To: Patrick Browne <[email protected]>, The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Understanding type variables in
Haskell class declarations
Message-ID:
<can+tr42w74bbh6so4u_cikt+fevfuutg7hbs66x_erhemx4...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
1, a and b are distinct types. However b is of kind * while a is of kind *
-> *, which means it takes a type and returns a type. That means that b
can be a type like Int, (), or Char, while a has to be a type like Maybe,
[], or (Either ()). That way they fit together into a type like (Maybe
Char) or [Int].
2. In the constraint Boats b p, there it says b and p are two types that
form an instance the Boats class (the class of boats and the things that
are on a boat. usually people). The next constraint says that h and (b p)
are each two types that satisfy the Houses constraint (the class of houses
and things that are in houses in this case boats, but boats have things
aboard them, so that has to be listed).
3. Haskell98 did not allow classes or instances with two type variables.
FlexibleInstances and MultiParamTypeClasses remove that limitation, and
they've been around for a very long time and will probably end up as part
of the standard at some point. You can read about them here, along with
other similar language features.
http://downloads.haskell.org/~ghc/latest/docs/html/users_guide/glasgow_exts.html#class-declarations
On Mon, May 21, 2018 at 6:20 AM, PATRICK BROWNE <[email protected]>
wrote:
> I am trying to understand how to interpret type variables in Haskell
> class declarations from a paper
> <http://citeseerx.ist.psu.edu/viewdoc/download;jsessionid=1EA31D76684217BC728F916144BC6C38?doi=10.1.1.109.6853&rep=rep1&type=pdf>
> .
> With respect to the code below I have the following questions:
> 1. What is the difference between "a b" in the header of the Container
> class and "a b" in the signature of the class methods? Does the whitespace
> in header mean 2 distinct types and in the methods mean function
> application?
> 2. In the Boathouse class what is the difference between the first
> ocurance of "b p" and the second bracketed "(b p)"?
> 3. When I try to make instance of these classes I seem to need
> FlexibleInstances. Why is this?
>
>
>
> {-# LANGUAGE MultiParamTypeClasses #-}
> -- Containers a b stands for all container types a holding things of type
> b.
> -- from :info command a has kind *->*, b has kind *
> class Containers a b where
> insert :: b -> a b -> a b
> remove :: b -> a b -> a b
> whatsIn :: a b -> [b]
>
>
> class Surfaces a b where
> put :: b -> a b -> a b
> takeOff :: b -> a b -> a b
> whatsOn :: a b -> [b]
>
> -- from :info command "p" has kind *, "h" and "b" have kind *->*
> class People p
> class Containers h p => Houses h p where
> class (People p, Surfaces h p) => Boats h p where
> class (Boats b p,Houses h (b p)) => BoatHouses h b p where
> class (People p, Houses h (b p),Boats b p) => HouseBoats h b p
>
> This email originated from DIT. If you received this email in error,
> please delete it from your system. Please note that if you are not the
> named addressee, disclosing, copying, distributing or taking any action
> based on the contents of this email or attachments is prohibited.
> www.dit.ie
>
> Is ó ITBÁC a tháinig an ríomhphost seo. Má fuair tú an ríomhphost seo trí
> earráid, scrios de do chóras é le do thoil. Tabhair ar aird, mura tú an
> seolaí ainmnithe, go bhfuil dianchosc ar aon nochtadh, aon chóipeáil, aon
> dáileadh nó ar aon ghníomh a dhéanfar bunaithe ar an ábhar atá sa
> ríomhphost nó sna hiatáin seo. www.dit.ie
>
> Tá ITBÁC ag aistriú go Gráinseach Ghormáin – DIT is on the move to
> Grangegorman <http://www.dit.ie/grangegorman>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20180521/eba1586e/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 119, Issue 13
******************************************