From 50295 at web.de Sat Feb 10 14:48:07 2018 From: 50295 at web.de (Olumide) Date: Sat, 10 Feb 2018 14:48:07 +0000 Subject: [Haskell-beginners] Join'ing a State Monad, example from LYH Message-ID: Dear List, I've been stumped for a few months on the following example, from chapter 13 of LYH http://learnyouahaskell.com/for-a-few-monads-more#useful-monadic-functions runState (join (State $ \s -> (push 10,1:2:s))) [0,0,0] I find the following implementation of join in the text is hard to understand or apply join :: (Monad m) => m (m a) -> m a join mm = do m <- mm m In contrast, I find the following definition(?) on Haskell Wikibooks https://en.wikibooks.org/wiki/Haskell/Category_theory#Monads join :: Monad m => m (m a) -> m a join x = x >>= id easier to understand, and although I can apply it to the following Writer Monad example, in the same section of LYH, runWriter $ join (Writer (Writer (1,"aaa"),"bbb")) I cannot apply it to the State Monad example. Regards, - Olumide From fa-ml at ariis.it Sat Feb 10 15:25:40 2018 From: fa-ml at ariis.it (Francesco Ariis) Date: Sat, 10 Feb 2018 16:25:40 +0100 Subject: [Haskell-beginners] Join'ing a State Monad, example from LYH In-Reply-To: References: Message-ID: <20180210152540.llwsh53dgobkw3i7@x60s.casa> On Sat, Feb 10, 2018 at 02:48:07PM +0000, Olumide wrote: > I find the following implementation of join in the text is hard to > understand or apply > > join :: (Monad m) => m (m a) -> m a > join mm = do > m <- mm > m Hello Olumide, remember that: join :: (Monad m) => m (m a) -> m a join mm = do m <- mm m is the same as: join :: (Monad m) => m (m a) -> m a join mm = mm >>= \m -> m In general remember that when you have a "plain" value, the last line of a monadic expression is often: return someSimpleVal So: monadicexpr = do x <- [4] return x -- can't just write `x` When you have a monad inside a monad, you can just "peel" the outer layer and live happily thereafter: monadicexpr = do x <- [[4]] x -- result will be: [4], no need to use return -- because [4] (and not 4) is still a -- list monad As for State, remember that State is: data State s a = State $ s -> (a, s) -- almost So a function that from a state s, calculates a new state s' and returns a value of type `a`. When we use the bind operator in a do block, it's like we're extracting that value of type `a` monadicexpr = do x <- someState return x -- again we need to wrap this value -- before returning it, this state being -- -- \s -> (x, s) -- -- i.e. we do nothing to the parameter state -- and place `x` as a result. -- Same trick there, if `x` is actually a State-inside-State (e.g. of type `State s (State s a)`), there is no need for wrapping anymore. Does this make sense? -F From patrick.browne at dit.ie Wed Feb 21 17:15:10 2018 From: patrick.browne at dit.ie (PATRICK BROWNE) Date: Wed, 21 Feb 2018 17:15:10 +0000 Subject: [Haskell-beginners] Viewing desugared classes and instances Message-ID: In the Haskell litrature desugaring of type clases to a data type is mentioned. For example: class Foo a where quux :: a -> Int muux :: a -> Bool Desugared to data FooD a = FooD -- class Foo a where { quuxD :: a -> Int -- quux :: a -> Int , muuxD :: a -> Bool -- muux :: a -> Bool } Is there any way using core dumps to actuall view the desugring of classes, sub-classes, and instances, in my own code? I have tried: ghc -c -ddump-ds Foo.hs But I cannot understand the output. Thanks, Pat -- 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: From frederic-emmanuel.picca at synchrotron-soleil.fr Fri Feb 23 15:11:27 2018 From: frederic-emmanuel.picca at synchrotron-soleil.fr (PICCA Frederic-Emmanuel) Date: Fri, 23 Feb 2018 15:11:27 +0000 Subject: [Haskell-beginners] soap client python -> haskell Message-ID: Hello, I try to reproduce this kind of python code into haskell --- python -- whcih use the suds module cj = CookieJar() url_opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) transport = HttpAuthenticated(username=self.getIspybUserName(), password=self.getIspybPassWord()) service_name = "ToolsForCollectionWebService" url = "http://195.221.10.20/ispyb-ws/ispybWS/ToolsForCollectionWebService?wsdl" collectionWSClient = Client(url, transport=transport, timeout=3) collect_params = collectionWSClient.service.findDataCollection(dataCollectionId)--- --- Has you can see, I create a Transport whcih need an Authentification and also I need to use a cookieJar in oder to manage the connection. The a soap client is instanciated from the url and with this transport. Then the findDatacollection service is called. Now I would like to reproduce this with Haskell and the soap package (or not if it is easier without) I started like this getDataCollection :: Transport -> Int -> IO Response getDataCollection t i = invokeWS t url () body parser where url = "http://195.221.10.20/ispyb-ws/ispybWS/ToolsForCollectionWebService?wsdl" -- ?wsdl/findDatacollection" body = elementA "ToolsForCollectionWebService" [("xmlns", "findDataCollection")] $ element "dataCollectionID" i parser = StreamParser . flaxTag "" $ response response = Response <$> flaxContent "filePath" main :: IO () main = do -- Initial one-time preparations. transport <- initTransportWithM defaultManagerSettings url pure pure response <- getDataCollection transport dataCollectionID print response And When I run this I have this message autoprocessing-exe: HttpExceptionRequest Request { host = "xxx.xxx.xxx.xxx" port = 80 secure = False requestHeaders = [("Content-Type","text/xml; charset=utf-8"),("SOAPAction","http://195.221.10.20/ispyb-ws/ispybWS/ToolsForCollectionWebService?wsdl")] path = "/ispyb-ws/ispybWS/ToolsForCollectionWebService" queryString = "" method = "POST" proxy = Nothing rawBody = False redirectCount = 10 responseTimeout = ResponseTimeoutMicro 15000000 requestVersion = HTTP/1.1 } TlsNotSupported I know that I do not want the https, the url is http and not https. now I do not know how to modify this in order to deal with the authentification and the cookiesJar. It seems here that proxy is Nothing so I hope thqht it will use the http[s]_proxy environment variable. thanks for your help. Frederic