From frederic-emmanuel.picca at synchrotron-soleil.fr Sun Aug 4 09:57:28 2019 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Sun, 4 Aug 2019 09:57:28 +0000 Subject: [Haskell-beginners] Storable which is only Peekable Message-ID: Hello, I would like to know what is the best way to create a type which is only peekable and pokable. When I use Storable, I "need" to define peek and poke and ghc complain that I did not defined the poke part. So how can I write something nice. Cheers Frederic #include "hkl-binoculars.h" data Space = Space (ForeignPtr Space) Int deriving Show foreign import ccall safe "fromImage" c_fromImage :: Ptr Double -> Int -> Ptr Double -> Ptr Int -> Int -> Ptr Word16 -> Ptr Int -> Int -> IO (Ptr Space) foreign import ccall unsafe "&space_free" c_space_free :: FunPtr (Ptr Space -> IO ()) instance Storable Space where alignment _ = #{alignment struct space_t} sizeOf _ = #{size struct space_t} peek ptr = Space <$> newForeignPtr c_space_free ptr <*> #{peek struct space_t, ndim} ptr From jcb at iteris.com Wed Aug 14 17:59:14 2019 From: jcb at iteris.com (Jeff C. Britton) Date: Wed, 14 Aug 2019 17:59:14 +0000 Subject: [Haskell-beginners] Network PortNumber deprecation warning Message-ID: I have just installed Haskell using Stack on Windows. I wanted to try and write some code to do network programming with TCP/IP. I found a simple example on Stack Overflow to start me off. I'm having some problems with PortNumber and deprecated warnings. I don't know how to modify the code to be deprecation free. stack install network - installed version 2.8.0.1 ------------------------- package.yaml network >= 2.8.0.1 --------------------------- The following code gives a deprecation warning, but ultimately my sample compiles and runs. import qualified Network import qualified Network.Socket main = Network.withSocketsDo $ do handle <- Network.connectTo "192.168.1.2" (Network.PortNumber 7200) talk handle `finally` hClose handle D:\work\hsSocket\app\Main.hs:14:46: warning: [-Wdeprecations] In the use of data constructor `PortNumber' (imported from Network): Deprecated: "The high level Network interface is no longer supported. Please use Network.Socket." ----------------------------------------- So, now I try and use Network.Socket as the warning indicates. main = Network.withSocketsDo $ do handle <- Network.connectTo "192.168.1.2" (Network.Socket.PortNumber 7200) talk handle `finally` hClose handle D:\work\hsSocket\app\Main.hs:15:46: error: Not in scope: data constructor `Network.Socket.PortNumber' Module `Network.Socket' does not export `PortNumber'. | 15 | handle <- Network.connectTo "192.168.1.2" (Network.Socket.PortNumber 7200) -------------- next part -------------- An HTML attachment was scrubbed... URL: From tanuki at gmail.com Fri Aug 16 17:22:57 2019 From: tanuki at gmail.com (Theodore Lief Gannon) Date: Fri, 16 Aug 2019 10:22:57 -0700 Subject: [Haskell-beginners] Network PortNumber deprecation warning In-Reply-To: References: Message-ID: You may have figured this out by now, but according to the docs, the error is correct: PortNumber exposes no constructor at all. Instead, it has a Num instance; you should be able to just use the literal 7200 there. This strikes me as a highly questionable decision on the part of the module authors, but it is at least convenient. On Wed, Aug 14, 2019, 10:59 AM Jeff C. Britton wrote: > I have just installed Haskell using Stack on Windows. > > I wanted to try and write some code to do network programming with TCP/IP. > > I found a simple example on Stack Overflow to start me off. > > I’m having some problems with PortNumber and deprecated warnings. > > I don't know how to modify the code to be deprecation free. > > > > stack install network – installed version 2.8.0.1 > > > > ------------------------- > > package.yaml > > network >= 2.8.0.1 > > --------------------------- > > > > The following code gives a deprecation warning, but ultimately my sample > compiles and runs. > > > > import qualified Network > > import qualified Network.Socket > > > > main = Network.withSocketsDo $ do > > handle <- Network.connectTo "192.168.1.2" (Network.PortNumber 7200) > > talk handle `finally` hClose handle > > > > D:\work\hsSocket\app\Main.hs:14:46: warning: [-Wdeprecations] > > In the use of data constructor `PortNumber' > > (imported from Network): > > Deprecated: "The high level Network interface is no longer supported. > Please use Network.Socket." > > > > > > ----------------------------------------- > > So, now I try and use Network.Socket as the warning indicates. > > > > main = Network.withSocketsDo $ do > > handle <- Network.connectTo "192.168.1.2" (Network.Socket.PortNumber > 7200) > > talk handle `finally` hClose handle > > > > D:\work\hsSocket\app\Main.hs:15:46: error: > > Not in scope: data constructor `Network.Socket.PortNumber' > > Module `Network.Socket' does not export `PortNumber'. > > | > > 15 | handle <- Network.connectTo "192.168.1.2" > (Network.Socket.PortNumber 7200) > > > _______________________________________________ > Beginners mailing list > Beginners at haskell.org > http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners > -------------- next part -------------- An HTML attachment was scrubbed... URL: From jcb at iteris.com Fri Aug 16 22:13:38 2019 From: jcb at iteris.com (Jeff C. Britton) Date: Fri, 16 Aug 2019 22:13:38 +0000 Subject: [Haskell-beginners] Network PortNumber deprecation warning In-Reply-To: References: Message-ID: The Network module is deprecated. I didn’t really get that from the warning, I thought it was just about PortNumber. From Hackage: “”” Milestones 2.7 See https://github.com/haskell/network/issues/296 • [x] Making Network deprecated • [x] Making Network.BSD deprecated • [x] Making MkSocket deprecated “”” ---- From: Beginners [mailto:beginners-bounces at haskell.org] On Behalf Of Theodore Lief Gannon Sent: Friday, August 16, 2019 10:23 AM To: The Haskell-Beginners Mailing List - Discussion of primarily beginner-level topics related to Haskell Subject: Re: [Haskell-beginners] Network PortNumber deprecation warning You may have figured this out by now, but according to the docs, the error is correct: PortNumber exposes no constructor at all. Instead, it has a Num instance; you should be able to just use the literal 7200 there. This strikes me as a highly questionable decision on the part of the module authors, but it is at least convenient. On Wed, Aug 14, 2019, 10:59 AM Jeff C. Britton wrote: I have just installed Haskell using Stack on Windows. I wanted to try and write some code to do network programming with TCP/IP. I found a simple example on Stack Overflow to start me off. I’m having some problems with PortNumber and deprecated warnings. I don't know how to modify the code to be deprecation free.   stack install network – installed version 2.8.0.1   ------------------------- package.yaml network >= 2.8.0.1 ---------------------------   The following code gives a deprecation warning, but ultimately my sample compiles and runs.   import qualified Network import qualified Network.Socket   main = Network.withSocketsDo $ do   handle <- Network.connectTo "192.168.1.2" (Network.PortNumber 7200)   talk handle `finally` hClose handle   D:\work\hsSocket\app\Main.hs:14:46: warning: [-Wdeprecations]     In the use of data constructor `PortNumber'     (imported from Network):     Deprecated: "The high level Network interface is no longer supported. Please use Network.Socket."     ----------------------------------------- So, now I try and use Network.Socket as the warning indicates.   main = Network.withSocketsDo $ do   handle <- Network.connectTo "192.168.1.2" (Network.Socket.PortNumber 7200)   talk handle `finally` hClose handle   D:\work\hsSocket\app\Main.hs:15:46: error:     Not in scope: data constructor `Network.Socket.PortNumber'     Module `Network.Socket' does not export `PortNumber'.    | 15 |   handle <- Network.connectTo "192.168.1.2" (Network.Socket.PortNumber 7200)   _______________________________________________ Beginners mailing list mailto:Beginners at haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners ATTENTION: This email is from an external source. Always use caution when opening attachments or clicking links from unknown senders or when receiving unexpected emails. From frederic-emmanuel.picca at synchrotron-soleil.fr Tue Aug 27 07:19:25 2019 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Tue, 27 Aug 2019 07:19:25 +0000 Subject: [Haskell-beginners] how to convert an array of foreignPtr a into a list of Ptr a Message-ID: Hello, I am writing some code whcih use FFI. one of my C functions has an array of pointer has imput extern HklBinocularsCube *hkl_binoculars_cube_new(int32_t n_spaces, const HklBinocularsSpace **spaces); from Haskell, I have a list of ForeignPtr so my question how can I have something like withForeignPtr for an array of ForeignPtr [ForeignPtr a] -> ([Ptr a] -> IO b) -> IO b Thanks for your help. Frederic